CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Location
    Argentina....
    Posts
    118

    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#

  2. #2
    Join Date
    Dec 2004
    Posts
    35

    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.

  3. #3
    Join Date
    Sep 2003
    Location
    Argentina....
    Posts
    118

    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#

  4. #4
    Join Date
    Oct 2001
    Location
    Melbourne, Australia
    Posts
    576

    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.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Search String No Case Sensitive

    Quote 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...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured