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.
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.
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.