Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

case sensitive

case sensitive

  • Please log in to reply
14 replies to this topic

#13 Althaz

Althaz

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 21 November 2008 - 04:31 AM

Obviously all of those work, if you know the string you want to compare thing to, you don't need to create a variable just to compare (I'm pretty sure, the program I made today seems to work, so I suspect this is right).

eg:

string input = HeresSomethingIPreparedEarlier();
if (input.ToLower() == "cake")
    return "pie";

I suspect some of those other functions are there so Java programmers feel more comfortable (eg: in Java you have to use .equals() when comparing a variable string (eg string cake = "pie") to a constant (eg: "pie").

Edited by Althaz, 21 November 2008 - 04:34 AM.
lol, left the closing bracket off the if statement...n00bish.

  • 0

#14 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 21 November 2008 - 04:42 AM

You guys should read:

Will Asrari - String.Compare() versus String.Equals()

then take a look at: New Recommendations for Using Strings in .NET 2.0

Read some of the string comparison methods. In particular this Official MS statement about ToUpper and ToLower:

Users should most certainly be careful when using these functions, since forcing a string to a certain case is often used as a small normalization for comparing strings irrespective of case. If so, consider using a case-insensitive comparison.


I still stand by my original statement that you should use String.Compare and pass the third operator to ignore case. Pass the fourth operator as the current/local language and your strings work internationally.

If you wanted to compare a variable against a known string:

if (String.Compare(input, "cake", true) == 0) {....}

  • 0

#15 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 21 November 2008 - 11:02 AM

lol, n00bs are taught that method in school when they learn .NET, as it is the proper method.

You are just arguing to increase your contest points. I believe I have seen you use my method before.

Posted via CodeCall Mobile

Incorrect on both counts. First, the contest has finished. Secondly, I have never used string.Compare() before in my memory. You fail, lulz.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?





Also tagged with one or more of these keywords: case sensitive

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download