Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,432 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,919 people online right now. Registration is fast and FREE... Join Now!




STRINGS

 
Reply to this topicStart new topic

STRINGS

tangy
14 Jan, 2008 - 02:55 AM
Post #1

New D.I.C Head
*

Joined: 8 Jan, 2008
Posts: 8

hi everyone. i need some help with regard to c++ programming.

How to compare string in non case sensitive mode?
User is offlineProfile CardPM
+Quote Post

VernonDozier
RE: STRINGS
14 Jan, 2008 - 03:18 AM
Post #2

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 46

Well you can use the "toupper" or "tolower" functions from the cctype library to convert all the letters in the string to upper or lower case one character at a time, then do whatever string comparison you want to do.
User is offlineProfile CardPM
+Quote Post

tangy
RE: STRINGS
14 Jan, 2008 - 03:21 AM
Post #3

New D.I.C Head
*

Joined: 8 Jan, 2008
Posts: 8

can u show me a sample program?
User is offlineProfile CardPM
+Quote Post

RodgerB
RE: STRINGS
14 Jan, 2008 - 03:38 AM
Post #4

D.I.C Lover
Group Icon

Joined: 21 Sep, 2007
Posts: 2,132



Thanked: 17 times
Dream Kudos: 2200
Expert In: Dot Net Technologies

My Contributions
We won't write code for you (its in the rules), however I suggest that you follow VernonDozier's advice and loop through all elements in the string, set the charactors to lower or uppercase, then compare the results. smile.gif
User is offlineProfile CardPM
+Quote Post

WXY
RE: STRINGS
14 Jan, 2008 - 05:50 AM
Post #5

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
or you just use the stdlib function "stricmp" in conjunction with basic_string::c_str()

This post has been edited by WXY: 14 Jan, 2008 - 05:50 AM
User is offlineProfile CardPM
+Quote Post

Bench
RE: STRINGS
14 Jan, 2008 - 09:43 AM
Post #6

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 630



Thanked: 16 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
QUOTE(WXY @ 14 Jan, 2008 - 01:50 PM) *

or you just use the stdlib function "stricmp" in conjunction with basic_string::c_str()

There is no such function as stricmp anywhere in standard C or C++. The only way to do this in standard C++ is to roll your own.
User is offlineProfile CardPM
+Quote Post

carltech
RE: STRINGS
14 Jan, 2008 - 02:18 PM
Post #7

New D.I.C Head
Group Icon

Joined: 19 Oct, 2007
Posts: 42


Dream Kudos: 25
My Contributions
QUOTE(Bench @ 14 Jan, 2008 - 10:43 AM) *

There is no such function as stricmp anywhere in standard C or C++. The only way to do this in standard C++ is to roll your own.

There is a function known as strcmp and one known as strncmp in C++ and it is under the string header file

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: STRINGS
14 Jan, 2008 - 02:55 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I think his point was that the mentioned stricmp() function is not part of the standard library - not the the other 2 did not exist.
User is offlineProfile CardPM
+Quote Post

WXY
RE: STRINGS
14 Jan, 2008 - 06:05 PM
Post #9

D.I.C Head
Group Icon

Joined: 2 Jan, 2008
Posts: 85


Dream Kudos: 50
My Contributions
arg, just realized it lol. Teaches me to never ever trust Microsoft on accurately documenting something that it doesn't own...
User is offlineProfile CardPM
+Quote Post

carltech
RE: STRINGS
14 Jan, 2008 - 06:50 PM
Post #10

New D.I.C Head
Group Icon

Joined: 19 Oct, 2007
Posts: 42


Dream Kudos: 25
My Contributions
I was trying to point out where and what the functions were. no offense but i knew what he was saying.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: STRINGS
15 Jan, 2008 - 05:24 AM
Post #11

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
No offense taken sir - I merely mentioned it because the thread deals with case insensitive string comparisons, and neither strcmp() nor strncmp provide this functionality. I had assumed that the original poster new about the standard functions, but had not mentioned them since they in no way provide him/her with a soltuion.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 05:01AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month