"csharpula csharp" wrote:
>
Hello,
I am trying to add a \n to Settings in c#. But it dooesn't recognize it
as \n (string) How can I solve this? Thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Hi,
If you are putting "\n" inside a string setting it appears to be transformed
to "\r\n ". This is because you are putting \n into an xml
which will end up looking like
<Namespace.Properties.Settings>
<setting name="Setting" serializeAs="String">
<value>
</value>
</setting>
</Namespace.Properties.Settings>
When you read from the xml you will end up with the part between <valueand
</valuewhich is correctly interpreted as "\r\n " ( a newline
and indentation )
On windows systems \r\n is the code for newline and even though \n may
sometimes be accepted as newline, it is not guaranteed to. The framework
will translate the incorrectly spelled newline character to a proper one,
which is why you get \r\n back even though you put \n in.
If you are creating an OS independent assembly, use Environment.Newline.
This will translate to \r\n or \n based on the OS the assembly is running on.
If you are streaming to/from non windows systems and need to determine if \n
should be used you may need a flag or store the value in a binary file.
--
Happy Coding!
Morten Wennevik [C# MVP]