I'm trying to parse certain text files and it would be easier if the contents where lower case with no punctuation, etc. So I was curious if c++ had anything similar to the unix tr command?
I'm trying to parse certain text files and it would be easier if the contents where lower case with no punctuation, etc. So I was curious if c++ had anything similar to the unix tr command?
You can use tolower. Just don't forget to cast the output as a character since its return type is an integer. Or you could use it in a transform function adapter with a string type which wouldn't require you to do casting. Or you could use the two parameter version of tolower which takes the beginning and end pointers of a string.
[edit]
To get rid of the punctuation and stuff, however, you would have to write your own specific code. It would probably be easier on you just to use tr to preprocess the text then work with that.
that would work fine for the lower casing, but I wanted to do some other formatting as well in one big swoop, like tr allows...I might have to just parse it char by char though
I'm afraid c++ is not the most convenient language for string processing. If you want an easy text processing interface, the best way would be to use perl or python to process the text, then have it interface with a c++ module to do whatever speed dependent task you want done.
Hmm..have a good point there...what about embeding Perl in C++, is that doable without too much hasle?
I don't know much about perl but with python, it's quite complicated to embed python in c++.
I do it the other way around. I call c++ modules from within python.
Try this:
http://www.swig.org
For what amounts to a couple of lines of code, trying to add in say perl is an awful lot of work.
Only lowercase letters -
Code:if ( isalpha(ch) ) { ch = tolower(ch); // You're home now, do what you want }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.