The
Contains
method uses an ordinal comparison:
public bool Contains(string value)
{
return this.IndexOf(value, StringComparison.Ordinal) >= 0;
}
Unfortunately, there isn't an overload of the
Contains
method which accepts a
StringComparison
option.
Fortunately, it's easy to write your own:
public static class StringExtensions
{
public static bool Contains(this string source, string value, StringComparison comparisonType)
{
if (source == null) throw new ArgumentNullException("source");
return source.IndexOf(value, comparisonType) >= 0;
}
}
Then you just need to call the extension method passing in a suitable
StringComparison
option:
private void selectWords(string fullText, string searchText)
{
string[] words = fullText.Split(' ');
ArrayList str = new ArrayList();
foreach (var word in words)
{
if (word.Contains(searchText, StringComparison.CurrentCulture))
{
richTextBox1.Find(word, 0, richTextBox1.TextLength, RichTextBoxFinds.None);
richTextBox1.SelectionBackColor = Color.Green;
str.Add(richTextBox1.SelectedText);
}
}
}