Newline "\n" - how to store and retrive on a single line in text file.
-
Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash
-
Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash
Are you writing the two characters backslash-n to the file? Or the byte 0A (written as '\n' in C)? If it's the first, then you're seeing exactly what you should be - the two characters backslash and n - because that's what's in the file. If you want this to be a newline in the CString, you'll need to replace backslash-n with '\n' after reading it from the file. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Are you writing the two characters backslash-n to the file? Or the byte 0A (written as '\n' in C)? If it's the first, then you're seeing exactly what you should be - the two characters backslash and n - because that's what's in the file. If you want this to be a newline in the CString, you'll need to replace backslash-n with '\n' after reading it from the file. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Thanks for your suggestion Michael. As you suggested I am currently doing it as - str.Replace(CString("\\n"),CString("\n")); simillarly for \", \a,\b etc etc. Shouldn't there be any generic way to handle all the escape sequences? - Suyash
Suyash wrote:
Shouldn't there be any generic way to handle all the escape sequences?
You might be able to cook up a regex, but Replace() calls would be clearer IMO. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Hello, Let me briefly explain the scenario before putting up my query. For internationalization purposes, we store all our strings in a text file. for some reasons we dont use the string tables. and a single string may contain one or more "\n". When I try to load a string form the text file in to CString variable, its not recognizing "\n" specified in the text file as newline character but as if "\\n" is specified. I hope the issue is clear. Your comments in this regard would be highly appreciated. Thanks in advance! Suyash