Nope.
Here is a shortened version:
Making it the same length. Also, in your method, n00bs might not know why you are comparing the value returned to zero, or what the boolean parameter you supply is.Code:string s1 = "YEs"; string s2 = "YES"; if (s1.ToLower() == s2.ToLower()) { //They match }
Therefore, my one is much better. You fail, lulz.
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
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:
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").Code:string input = HeresSomethingIPreparedEarlier(); if (input.ToLower() == "cake") return "pie";
Last edited by Althaz; 11-21-2008 at 04:34 AM. Reason: lol, left the closing bracket off the if statement...n00bish.
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:
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.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.
If you wanted to compare a variable against a known string:
Code:if (String.Compare(input, "cake", true) == 0) {....}
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks