Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitive string search

What is the quickest most efficient way to search text for words using non-casesensitive search.

E.g here is my text to be searched :

string textTosearch = "Here is a paragraph or Some text. Here is some more text".

If I wanted to find the indexes of "Some" and "some", is there a .Net class that does this or would I need to use something like regular expressions.

Your thoughts are much appreciated.

I'm using visual studio 2008.

like image 537
TonyNeallon Avatar asked Mar 05 '10 16:03

TonyNeallon


1 Answers

Take a look at the IndexOf method:

textTosearch.IndexOf("some", StringComparison.OrdinalIgnoreCase);

Other overloads of this method allow you to specify a start index and a number of characters to examine.

like image 88
Darin Dimitrov Avatar answered Nov 07 '22 15:11

Darin Dimitrov