I am just curious about the title.
String a = "abc\ndef";
Console.Writeline(a);
The output is
abc
def
Then I stored that value into an ini file and retrieved it from there.
ini.iniwritevalue("a", "a", a);
string b = ini.inireadvalue("a", "a");
Then I showed it on the console. The result is the following:
abc\ndef
Why is \n
not working after I retrieved it from the ini file?
P.S. I have a ini.dll file. Our company开发者_开发技巧 is using that dll to read and write ini files.
The interpretation of the \n escape code in your source code is done by the compiler when parsing the source file.
If you just read in a file as "data" at runtime, no such interpretation is necessarily going to occur.
You may need to find or write a function which takes a string containing escape sequences and converts them to binary values (\n usually becomes 0x0a)
This is because \n
in C# is not just a \
and an n
, but an escape sequence with a special meaning. \n
is considered a single character and is a line ending. You will not get it when you simply read a \
and an n
from a file.
Possibly, you read \\n
from there. \\
is also an escape sequence which means the \
character. All you have to do is replace \\n
with \n
, and it'll be okay.
string s = ... //get the value
s = s.Replace("\\n", "\n");
You need to escape the slash when you write the value, like this:
abc\\ndef
精彩评论