Reputation: 55604
How can I get how many times a string occurs in a textbox?
I thought the find function would return the number of times found but it seems to return the location of it.
Upvotes: 4
Views: 8748
Reputation: 888185
You can call Split
, like this:
(" " + textBox1.Text + " ").Split(New String() { inputString }, StringSplitOptions.None);
Alternatively, you can keep calling IndexOf
with the startIndex equal to the previous call's return value + 1 until it returns -1.
Upvotes: 0