Hello guys
What would be the best way to separate strings by '\n' and escape '\r's? To use boost::tokenizer, make own function or just use any already made function?
Thanks for help
Printable View
Hello guys
What would be the best way to separate strings by '\n' and escape '\r's? To use boost::tokenizer, make own function or just use any already made function?
Thanks for help
If you are just doing this on like \r\n sequences, then you could just replace every '\n' with an 'r' and the character before it with a '\\'. I don't know what you mean by seperate, but something like strtok modifies the string, so boost::tokenizer could be appropriate.
Assuming you're working with C-style strings (character arrays)...
You should be able to do almost everything you want with the functions in <cstring>. Most of these functions start with str... strncpy() etc.
You may need to write some functions on your own, and you may need to insert /n manually in some cases.
You should not need /r. C-style strings are null-terminated (/n or zero-value character). If you save strings to disk in text mode, the /n will be automatically be converted to carriage return and/or line feed as required by your particular system. If you save in binary mode, you will have to convert the string-termination manually.
I think the OP wants to turn "foo\r" + "bar" into "foo\\\r\nbar".
In that case, again assuming you're using C-style character arrays, you could use memmove() to shift all the characters to the right to allow you to add in a '\\'. And strcat() will append one string onto the end of another.
What if I just use boost tokenizer separator with ("\n\r")? I heard boost::tokenizer isnt that fast..
Where did you hear that?