dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] String (case insensitive)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2014
    Posts
    285

    Resolved [RESOLVED] String (case insensitive)

    Hello.

    I am making a function to whisper other players in my game. To do so, the user types some letters which then gets compared with ListOfPlayersOnline to check for a string match, but right now that comparison is unfortunately case sensitive.

    Fwiw I want all characters to ignore case, not just the first. What would be the proper way to achieve this?

  2. #2
    Frenzied Member PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Newport, UK
    Posts
    1,197

    Re: String (case insensitive)

    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx is probably your best bet, you get to choose case sensitivity or not when comparing this way.

  3. #3
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: String (case insensitive)

    Use the overload of either String.Equals or String.Compare that takes a StringComparison argument and use one of the ignorecase values.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,723

    Re: String (case insensitive)

    If you're testing for equality then use String.Equals. String.Compare will give you a value that indicates the relative order of two Strings, which is irrelevant to you.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2014
    Posts
    285

    Re: String (case insensitive)

    Thanks, String.Equals with the proper overload will do nicely.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2014
    Posts
    285

    Re: String (case insensitive)

    This is what I ended up with:

    Code:
    If String.Equals(DictOfPlayersOnline.Values(i).Name, WhisperSearchString, StringComparison.CurrentCultureIgnoreCase) Then

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width