|
-
Jul 31st, 2003, 11:04 PM
#1
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.
-
Aug 1st, 2003, 01:09 AM
#2
Hyperactive Member
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.
-
Aug 1st, 2003, 05:06 AM
#3
Lively Member
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
-
Aug 1st, 2003, 09:44 AM
#4
to check how many words there are / build a string array , you can do this :
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not TextBox1.Text.IndexOf(" ") = -1 Then
Dim strString() As String = TextBox1.Text.Split(" ")
MessageBox.Show("The count of words in the textbox is: " & TextBox1.Text.Split(" ").GetUpperBound(0))
End If
End Sub
you can do the same to count the occurences of a particular string in the textbox , eg:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not TextBox1.Text.IndexOf("some-text") = -1 Then
MessageBox.Show("the string , [some-text] appears: & " & TextBox1.Text.Split("some-text").GetUpperBound(0) & " times in textbox1")
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|