|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
|
|||||
|
use the .ToUpper() method and compare with YES dang! Amr beat me to it!
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. My CodeCall Blog | My Personal Blog |
|
|||||
|
Hey, I'm glad people are helping each other. It's a GOOD thing.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. My CodeCall Blog | My Personal Blog |
|
|||||
|
Not saying that doesn't work but I've never seen it done like that: Code:
if("YEs".ToLower()=="yes".ToLower())return true;
Code:
string s1 = "YEs";
string s2 = "YES";
if(string.compare(s1.ToLower(),s2.ToLower())==0) {
// They Match
}
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
}
String.CompareOrdinal() will return the numeric Unicode values for each character compared String.Equals() returns a boolan value similar to using "=="
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Post a job on our freelance section! Paste between computers/devices and Collaborate on Code!. |
|
|||||
|
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
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Post a job on our freelance section! Paste between computers/devices and Collaborate on Code!. |
|
|||||
|
OK, here's my code then: Code:
string s1 = "YEs"; string s2 = "YES"; bool match = (s1.ToLower() == s2.ToLower()) ? true : false; Code:
string s1 = "YEs";
string s2 = "YES";
if(string.compare(s1, s2, true)==0) {
// They Match
}
|
|
|||||
|
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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog Post a job on our freelance section! Paste between computers/devices and Collaborate on Code!. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Switch Statement | ahmed | C and C++ | 3 | 11-07-2008 04:57 PM |
| Worst case analysis | Chinmoy | C Tutorials | 5 | 10-03-2008 10:40 AM |
| Design and implement a lexical analyzer written in C | ~bleach~ | C and C++ | 11 | 06-09-2008 10:52 AM |
| Please help me | yonghan | Visual Basic Programming | 4 | 05-13-2008 02:08 PM |
| Is MySQL case sensitive? | yooj | Database & Database Programming | 1 | 08-28-2007 07:45 AM |
Algorithms and Data Structures
Programming Language Popularity
Code Collaboration
Podnet IRC Network
AmpHosted
Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%