473,703 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compare without regard to case

Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".
Thanks,

-JKop
Jul 22 '05 #1
28 2270

"JKop" <NU**@NULL.NULL > schrieb im Newsbeitrag
news:ab******** **********@news .indigo.ie...
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".


stricmp(str1, str2);
Jul 22 '05 #2

"JKop" <NU**@NULL.NULL > wrote in message
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".


One way is to inherit from char_traits<... > and provide the necessary
overrides. Then use that class instead of std::string. This is discussed in
this GotW series - http://www.gotw.ca/gotw/029.htm
Sharad
Jul 22 '05 #3

"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2q******** *****@uni-berlin.de...

"JKop" <NU**@NULL.NULL > schrieb im Newsbeitrag
news:ab******** **********@news .indigo.ie...
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".


stricmp(str1, str2);


stricmp is not standard C or C++.

john
Jul 22 '05 #4

"JKop" <NU**@NULL.NULL > wrote in message
news:ab******** **********@news .indigo.ie...
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".
Thanks,

-JKop


There is no standard C++ function for doing that. You could write something
yourself using the toupper or tolower functions which operate on individual
characters.

john
Jul 22 '05 #5

"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2q******** *****@uni-berlin.de...

"JKop" <NU**@NULL.NULL > schrieb im Newsbeitrag
news:ab******** **********@news .indigo.ie...
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for
comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".


stricmp(str1, str2);


Isn't that non-standard ?
Jul 22 '05 #6
> stricmp is not standard C or C++.

Uh!? But strcmp is?
Jul 22 '05 #7

"Gernot Frisch" <Me@Privacy.net > wrote in message
news:2q******** *****@uni-berlin.de...
stricmp is not standard C or C++.


Uh!? But strcmp is?


Right.

john
Jul 22 '05 #8
John Harrison posted:

"JKop" <NU**@NULL.NULL > wrote in message
news:ab******** **********@news .indigo.ie...
Haven't been able to find such a thing.

Can anyone please inform me of a Standard C++ function for comparing two strings without regard to case. Both for
working with "char*", and with "std::strin g".
Thanks,

-JKop
There is no standard C++ function for doing that. You

could write something yourself using the toupper or tolower functions which operate on individual characters.

john


Okay not to be too "do stuff for me"ish, but if some-one
has already written such a function, could they please
copy-paste it here, or perhaps post the code for that
"stricmp" function.

Thanks,

-JKop
Jul 22 '05 #9
JKop <NU**@NULL.NULL > writes:
Okay not to be too "do stuff for me"ish, but if some-one
has already written such a function,

Functions like this have been posted here in the past, based around
lines like
transform(text. begin(),text.en d(),text.begin( ),toupper);
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
20652
by: MrCoder | last post by:
Hey guys, my first post on here so I'll just say "Hello everbody!" Ok heres my question for you lot. Is there a faster way to compare 1 byte array to another? This is my current code // Check for a match
3
1828
by: serge | last post by:
Is there a stored procedure to allow me to compare two SQL objects? In my case for example I want to compare two stored procedures on two different databases? If there is no SP that does comparison, would there be any code in SQL DMO that does this? How does someone learn SQL DMO? Does SQL Server 2000 have by default DMO learning material or I have to search for books?
3
21026
by: Matt | last post by:
if (123 > 33) will return true and if ("123" > 33) will return true So my question is, if the above behaviors are the same?? If string is a number, and compare with another number, it will be the same behavior as compare 2 numbers?
10
4231
by: tvn007 | last post by:
#include <iostream> #include <string> int main (void){ using namespace std; string STR =("TEST"); const std::string::size_type STR_SIZE = STR.size(); int count =0; while ( count <= STR_SIZE){
122
5294
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) { /* array differs from value, do something*/
49
14883
by: raju | last post by:
hi can we compare two integers without using relational operators (== != < <= > >=) thanks rajesh s
19
9515
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I have tried to print out by debug.writeline(). But the "==" operator results false, and string.Compare() results true. Somebody helps me!
1
3519
by: Linda | last post by:
Hi, Is there a way to do a "text" (rather than "binary") compareison with the "like" operator, without changing the global "Option Compare" setting? I don't want to risk breaking many, many lines of functional code just to get one "like" operation to behave as I wish. I want to check whether a single-character string is (a letter or number, INCLUDING diacritical letters) or whether it is (something else.)
0
193
by: Maric Michaud | last post by:
Le Friday 05 September 2008 00:14:37 Robert Dailey, vous avez écrit : This is the normal python way to compare string without case, and the idiomis not surprising. You''ll often see for loops written like this : for i in (e for e in iterable if predicate(e)) : ... If you fell hard to read you can break it on two lines :
0
8758
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8669
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9121
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4432
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2450
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.