settings

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

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!
 
csharpula csharp said:
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!

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 <value> and
</value> which 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top