Results 1 to 4 of 4

Thread: Searching for things in a string or textbox

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Searching for things in a string or textbox

    I have an Array of strings, I am using a Regex statement to split each word out of it and dynamicly put each 1 into the array.

    So "Hello world" would be

    s(0) = "Hello"
    s(1) = "world"

    After the code runs. Now my question is, how could I search a textbox or string with the statement WITHOUT knowing how many strings will be created within the array and then returning how many were found of out the total number of strings within the array.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    surely you would have created the array using the redim preserve and therefor already know the number of array elements after that it's a simple for loop using instring function to see if you have a match
    Last edited by RichardAtherton; Aug 1st, 2003 at 01:16 AM.

  3. #3
    Lively Member
    Join Date
    Sep 2002
    Location
    Belgium
    Posts
    99
    If you use an Icollection, then you can search through the array with contains.

    You can use add, remove, clear without redimming the array and so on. It's a VERY nice feature !

    HTH

    Bjorn

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    to check how many words there are / build a string array , you can do this :
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         If Not TextBox1.Text.IndexOf(" ") = -1 Then
    4.             Dim strString() As String = TextBox1.Text.Split(" ")
    5.             MessageBox.Show("The count of words in the textbox is: " & TextBox1.Text.Split(" ").GetUpperBound(0))
    6.         End If
    7.     End Sub
    you can do the same to count the occurences of a particular string in the textbox , eg:
    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         If Not TextBox1.Text.IndexOf("some-text") = -1 Then
    3.             MessageBox.Show("the string , [some-text] appears: & " & TextBox1.Text.Split("some-text").GetUpperBound(0) & " times in textbox1")
    4.         End If
    5.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width