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

#1 Siten0308

Siten0308

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 298 posts

Posted 19 November 2008 - 02:59 PM

Hello,

Really easy question for everyone,

what the the code to have the user input none case sensative example: user can input, yes YES yEs and still equal to whatever in a if and else statement?

Thank you
  • 0

#2 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 19 November 2008 - 05:38 PM

at last! someone to help

you can use this function "ToLower()"
this code will return true :
bool compare()
{
if("YEs".ToLower()=="yes".ToLower())return true;
else return false;
}

}
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 19 November 2008 - 05:49 PM

use the .ToUpper() method and compare with YES

dang! Amr beat me to it!
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 19 November 2008 - 05:52 PM

lol, youve helped lots of people including me...let me share the burden :)
  • 0
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#5 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 19 November 2008 - 05:56 PM

Hey, I'm glad people are helping each other. It's a GOOD thing.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#6 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 November 2008 - 06:44 AM

Not saying that doesn't work but I've never seen it done like that:

if("YEs".ToLower()=="yes".ToLower())return true;

I'm guessing "yes".ToLower() returns a string but I though the proper method was to use the String.Compare function? I could be wrong:

string s1 = "YEs";
string s2 = "YES";
if(string.compare(s1.ToLower(),s2.ToLower())==0) {
  // They Match
}

It is odd that 0 = true but anything above 0 or below is false.

Rather than using .ToLower() you can pass a third argument to string.compare to ignore case:

string s1 = "YEs";
string s2 = "YES";
if(string.compare(s1, s2, true)==0) {
  // They Match
}

You have other options as well:

String.CompareOrdinal() will return the numeric Unicode values for each character compared

String.Equals() returns a boolan value similar to using "=="
  • 0

#7 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 20 November 2008 - 09:43 AM

Your method is irrelevant, because ToLower() and ToUpper() work perfectly. -rep
  • 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?

#8 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 November 2008 - 10:39 AM

Now he has the option to choose. My method with passing the third param looks neater as well. Your post is irrelevant to his problem. -rep
  • 0

#9 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 20 November 2008 - 10:59 AM

OK, here's my code then:

string s1 = "YEs";
string s2 = "YES";
bool match = (s1.ToLower() == s2.ToLower()) ? true : false;

Your code:

string s1 = "YEs";
string s2 = "YES";
if(string.compare(s1, s2, true)==0) {
  // They Match
}

My one is neater. ---rep
  • 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?

#10 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 November 2008 - 11:58 AM

You'll still need an if statement in yours to diagnose "match" later, making your code one line longer than mine. Your code is inferior to mine not to mention slower.

Fail.
  • 0

#11 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 20 November 2008 - 12:19 PM

Nope.

Here is a shortened version:

string s1 = "YEs";
string s2 = "YES";
if (s1.ToLower() == s2.ToLower()) {
//They match
}

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.

Therefore, my one is much better. 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?

#12 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 20 November 2008 - 02:08 PM

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
  • 0





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