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?
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.