|
-
February 27th, 2005, 04:14 AM
#1
Search String No Case Sensitive
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
My history: QB->VB->TC++->VB->VC++->VC#
-
February 27th, 2005, 09:15 AM
#2
Re: Search String No Case Sensitive
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.
-
February 28th, 2005, 04:58 PM
#3
Re: Search String No Case Sensitive
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
My history: QB->VB->TC++->VB->VC++->VC#
-
February 28th, 2005, 05:06 PM
#4
Re: Search String No Case Sensitive
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.
-
March 1st, 2005, 03:51 AM
#5
Re: Search String No Case Sensitive
 Originally Posted by LiquidShadows
But is the IndexOf really case sensitive? Msdn doesen't say.
Yes, it says so:
This method performs a word (case-sensitive and culture-sensitive) search using the current culture.
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???
That's much more easier than creating a custom search function...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|