Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding strings case insensitive

Status
Not open for further replies.

gacaccia

Technical User
May 15, 2002
258
US
hi all,

i've seen some info here on how to compare strings without regard to case. however, what about finding strings without regard to case? is there a handy function for this, or do i need to build something from scratch?

thanks,

glenn
 
CString::CompareNoCase is one
you can also but the 2 variables into CStrings and call the MakeUpper funciton. Then do a find.

Matt
 
i'm not sure the first answers my question, as i need to find an instance of a string regardless of case, not compare two strings regardless of case. i can't compare until i've found.

the second approach would work with a slight modification, as i need to preserve the source string case, but i could make a duplicate of the source, turn that to upper case, do finds on it and replaces on the other. still, i was hoping there would be a simpler approach.

thanks,

glenn
 
>> what about finding strings without regard to case

ummm... finding them where? [bugeyed]

-pete
 
basically, i'm reading the content of a configuration file into a string. i then need to find all instances of a given path and change it to a new path. the given path could be mixed case, so i need to be able to find the path regardless of case, and then replace. but, i don't want to change case for anything else in the file.
 
First of all, my vote would go to not doing that in C++, but in something more like Perl.

If you must use C++, an easy, but inefficient, way to do it would be to save a copy of the config file in a string, copy that string, convert the copy to all upper case (or all lower case), then search for the pathname in the copy. Wherever you find it, replace that part of the original string with the new path. At that point, you'd need to make a new copy of the original string (since it changed), convert it to upper case, search and replace, then repeat as necessary. Write the string as the new config file.

There are, of course, other, more efficient, more elegant ways to handle it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top