Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C# Programming

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-19-2008, 04:59 PM
Programmer
 
Join Date: Jun 2008
Location: California, USA
Posts: 191
Rep Power: 5
Siten0308 will become famous soon enough
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 11-19-2008, 07:38 PM
amrosama's Avatar   
Code Warrior
/////////|||||\\\\\\\\\
 
Join Date: Aug 2007
Location: Giza, Egypt
Age: 20
Posts: 6,139
Blog Entries: 10
Rep Power: 52
amrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to all
Send a message via MSN to amrosama
Default 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;
}
}
__________________
Code:
<script type="text/javascript">
Amr.addEvent('graduation', function() {this.tween('life','cool');});
</script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-19-2008, 07:49 PM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: case sensitive

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-19-2008, 07:52 PM
amrosama's Avatar   
Code Warrior
/////////|||||\\\\\\\\\
 
Join Date: Aug 2007
Location: Giza, Egypt
Age: 20
Posts: 6,139
Blog Entries: 10
Rep Power: 52
amrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to allamrosama is a name known to all
Send a message via MSN to amrosama
Default Re: case sensitive

lol, youve helped lots of people including me...let me share the burden
__________________
Code:
<script type="text/javascript">
Amr.addEvent('graduation', function() {this.tween('life','cool');});
</script>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-19-2008, 07:56 PM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: case sensitive

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-20-2008, 08:44 AM
Jordan's Avatar   
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 18,359
Blog Entries: 90
Rep Power: 20
Jordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of light
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Default 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 "=="
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-20-2008, 11:43 AM
Xav's Avatar   
Xav Xav is offline
Code Slinger
 
Join Date: Mar 2008
Location: The North Pole
Posts: 13,210
Blog Entries: 13
Rep Power: 105
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-20-2008, 12:39 PM
Jordan's Avatar   
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 18,359
Blog Entries: 90
Rep Power: 20
Jordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of light
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-20-2008, 12:59 PM
Xav's Avatar   
Xav Xav is offline
Code Slinger
 
Join Date: Mar 2008
Location: The North Pole
Posts: 13,210
Blog Entries: 13
Rep Power: 105
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-20-2008, 01:58 PM
Jordan's Avatar   
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 18,359
Blog Entries: 90
Rep Power: 20
Jordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of lightJordan is a glorious beacon of light
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Default 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -5. The time now is 10:07 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

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%

Ads