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.
Regex.Matches(textBox1.Text, Regex.Escape(inputString)).Count
Import System.Text.RegularExpressions Regex provides best performance for simple searches, especially if you use the Compiled flag and precreate the regex object. But I never benchmarked this.inputString contains special characters. You need to call Regex.Escape.Regex.Matches(textBox1.Text, Regex.Escape(inputString)).Count.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.