Hi, i'm tring to do a simple word search in a string, to do so i use: Sentence.IndexOf(WordToSearch);
But if the sentence is "Hello World!", and Word = "hello", it returns -1...
Anyone knows a way to do a no case sensitive search??'
Thanks,
Diego
Printable View
Hi, i'm tring to do a simple word search in a string, to do so i use: Sentence.IndexOf(WordToSearch);
But if the sentence is "Hello World!", and Word = "hello", it returns -1...
Anyone knows a way to do a no case sensitive search??'
Thanks,
Diego
If you dont need to return the word or sentence with the original formatting hen you could just do Sentence..ToLower().IndexOf(WordToSearch.ToLower()); to make the entire sentence and word lowercase before the search.
But is the IndexOf really case sensitive? Msdn doesen't say.
Yeap!... it's case sensitive, but the problem is that i have to search and make a conditional remove, it's the only one way creating a copy of the Sentence and making all to lower, save the IndexOf position (if the Word was found), and delete it on the original Sentence???
Thanks,
Diego
you could make a custom function to do it yourself;
i.e loop through char by char, when you find a match on the first char, check the next, etc.
Yes, it says so:Quote:
Originally Posted by LiquidShadows
Quote:
This method performs a word (case-sensitive and culture-sensitive) search using the current culture.
That's much more easier than creating a custom search function... ;)Quote:
Yeap!... it's case sensitive, but the problem is that i have to search and make a conditional remove, it's the only one way creating a copy of the Sentence and making all to lower, save the IndexOf position (if the Word was found), and delete it on the original Sentence???