5

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.

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I was just doing some tests, and found that given both large and small amounts of text that Text.ToLower().Contains(Value.ToLower()) is quite a bit faster for case insensitive searching than the indexOf method. Maybe there is some drawback to doing it this way though that I am not aware of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.