locked
Special searching in string ?! RRS feed

  • Question

  • I have a textbox which contains some numbers and a "*" preceding each of the numbers. For example :

    *2*12*22*54*5*6 ...

    I also have another textbox that also contains (different) numbers with "*" preceding each of them like :

    *334*23*54*11*9*45 ...

    * Number of numbers in both the textboxes are the same. For example in the instance above it is 6 numbers


    I want to have a search method in which I give a number with its "*" , like *22 in the first textbox , then I want to know how many "*" are before the searched number ?

    For example, the number I want to search is *54.  I know that it is the forth "*" and number. but how to program my application to tell me this in a longer string of "*" and numbers ? because I can not tell it myself in a longer string, by counting each number ...

    After specifying the position of searched number in the first textbox (like : *54 is the forth number, so its position is the forth) , I want my application to tell me the number with the same position in the second textbox (in this case it is 11)

    ** I want to have an exact search method that doesn't make mistake finding both *2 and *22  when I search for only *2.





    • Edited by Kevin993 Wednesday, February 13, 2019 5:12 AM
    Wednesday, February 13, 2019 5:12 AM

Answers

  • Hi,

    Do you want this effect?

    Public Class Form1
        Dim array1 As String()
        Dim array2 As String()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "*2*12*22*54*5*6"
            TextBox2.Text = "*334*23*54*11*9*45"
            array1 = TextBox1.Text.Split("*")
            array2 = TextBox2.Text.Split("*")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim i = 0
    
            For Each t In array1
                If t <> TextBox3.Text.Substring(1) Then
                    i += 1
                Else
                    TextBox4.Text = array2(i)
                End If
            Next
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Wednesday, February 13, 2019 6:32 AM
    Wednesday, February 13, 2019 6:05 AM

All replies

  • Hi,

    Do you want this effect?

    Public Class Form1
        Dim array1 As String()
        Dim array2 As String()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "*2*12*22*54*5*6"
            TextBox2.Text = "*334*23*54*11*9*45"
            array1 = TextBox1.Text.Split("*")
            array2 = TextBox2.Text.Split("*")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim i = 0
    
            For Each t In array1
                If t <> TextBox3.Text.Substring(1) Then
                    i += 1
                Else
                    TextBox4.Text = array2(i)
                End If
            Next
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Kevin993 Wednesday, February 13, 2019 6:32 AM
    Wednesday, February 13, 2019 6:05 AM
  • Hi,

    Do you want this effect?

    Public Class Form1
        Dim array1 As String()
        Dim array2 As String()
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBox1.Text = "*2*12*22*54*5*6"
            TextBox2.Text = "*334*23*54*11*9*45"
            array1 = TextBox1.Text.Split("*")
            array2 = TextBox2.Text.Split("*")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim i = 0
    
            For Each t In array1
                If t <> TextBox3.Text.Substring(1) Then
                    i += 1
                Else
                    TextBox4.Text = array2(i)
                End If
            Next
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Exactly what I wanted! Thanks a million dude
    Wednesday, February 13, 2019 6:33 AM