Help with a Trim Function

Jul 2, 2011 at 11:58pm
Okay basically i need some help with a trim function with char*. There is a random newline character in some c style strings that is screwing up things like strcmp(), i.e. \n001584805 is not the same as 001584805. Does anyone know of an efficient way to get rid of that newline character after the char*'s have all been created? Any help would be greatly appreciated,
Jul 3, 2011 at 12:09am
The random newlines in the strings are my fault obviously, but the way the File im reading from is set up they are gonna be there unfortunately.
Jul 3, 2011 at 1:44am
You could put your char* into a std::string and use the string's find and erase functions. Then, you could delete your char* and reset it to the char* contained in the string.

If your requirements dictate that you could only use c style strings, then you would have to write your own removeNewlines function.
Jul 3, 2011 at 2:14am
closed account (S6k9GNh0)
There are various trim functions to use. You can simply iterate through the string until you find a new line character and delete it.
Last edited on Jul 3, 2011 at 10:25am
Jul 3, 2011 at 2:27am
Thanks i'll try creating a string and then using c_str() and see where that gets me.
Topic archived. No new replies allowed.