Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: case sensitive

  1. #1
    Siten0308's Avatar
    Siten0308 is offline Programming Professional
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    302
    Rep Power
    16

    Question case sensitive

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: case sensitive

    at last! someone to help

    you can use this function "ToLower()"
    this code will return true :
    Code:
    bool compare()
    {
    if("YEs".ToLower()=="yes".ToLower())return true;
    else return false;
    }
    }
    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"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  4. #3
    Join Date
    Jul 2006
    Posts
    16,475
    Blog Entries
    75
    Rep Power
    143

    Re: case sensitive

    use the .ToUpper() method and compare with YES

    dang! Amr beat me to it!
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

    Re: case sensitive

    lol, youve helped lots of people including me...let me share the burden
    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"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  6. #5
    Join Date
    Jul 2006
    Posts
    16,475
    Blog Entries
    75
    Rep Power
    143

    Re: case sensitive

    Hey, I'm glad people are helping each other. It's a GOOD thing.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #6
    Jordan Guest

    Re: case sensitive

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

    Code:
    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:

    Code:
    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:

    Code:
    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 "=="

  8. #7
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: case sensitive

    Your method is irrelevant, because ToLower() and ToUpper() work perfectly. -rep

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  9. #8
    Jordan Guest

    Re: case sensitive

    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

  10. #9
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: case sensitive

    OK, here's my code then:

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

    Code:
    string s1 = "YEs";
    string s2 = "YES";
    if(string.compare(s1, s2, true)==0) {
      // They Match
    }
    My one is neater. ---rep

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  11. #10
    Jordan Guest

    Re: case sensitive

    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.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is MySQL case sensitive?
    By yooj in forum Database & Database Programming
    Replies: 5
    Last Post: 01-24-2011, 11:45 AM
  2. Replies: 5
    Last Post: 10-27-2010, 12:25 AM
  3. switch case
    By kenex in forum C and C++
    Replies: 3
    Last Post: 02-01-2009, 08:18 PM
  4. Help with case
    By kresh7 in forum Visual Basic Programming
    Replies: 5
    Last Post: 03-16-2008, 11:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

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