+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 15

Thread: case sensitive

  1. #1
    Programming Professional Siten0308 will become famous soon enough Siten0308's Avatar
    Join Date
    Jun 2008
    Location
    California, USA
    Posts
    287

    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. #2
    Code Warrior
    /////////|||||\\\\\\\\\
    amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama's Avatar
    Join Date
    Aug 2007
    Location
    Pyramids st, Giza, Egypt
    Age
    21
    Posts
    8,181
    Blog Entries
    12

    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;
    }
    }

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,648
    Blog Entries
    57

    Re: case sensitive

    use the .ToUpper() method and compare with YES

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

  4. #4
    Code Warrior
    /////////|||||\\\\\\\\\
    amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama's Avatar
    Join Date
    Aug 2007
    Location
    Pyramids st, Giza, Egypt
    Age
    21
    Posts
    8,181
    Blog Entries
    12

    Re: case sensitive

    lol, youve helped lots of people including me...let me share the burden

  5. #5
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,648
    Blog Entries
    57

    Re: case sensitive

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

  6. #6
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

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

  7. #7
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  8. #8
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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

  9. #9
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  10. #10
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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.

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Switch Statement
    By ahmed in forum C and C++
    Replies: 3
    Last Post: 11-07-2008, 04:57 PM
  2. Worst case analysis
    By Chinmoy in forum C Tutorials
    Replies: 5
    Last Post: 10-03-2008, 10:40 AM
  3. Replies: 11
    Last Post: 06-09-2008, 10:52 AM
  4. Please help me
    By yonghan in forum Visual Basic Programming
    Replies: 4
    Last Post: 05-13-2008, 02:08 PM
  5. Is MySQL case sensitive?
    By yooj in forum Database & Database Programming
    Replies: 1
    Last Post: 08-28-2007, 07:45 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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