Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# MVC, reading carriage returns from web.config

Tags:

c#

asp.net-mvc

I am trying to put a list of delimiters in a web.config file, one of the delimiters is a carriage return - \r\n. The web.config entry looks like this -

<add key="Separators" value=" |,|;|\r\n"/>

I am trying to read in the list using a call like the following -

string[] MySeparators = ConfigurationManager.AppSettings ConfigSettings.PartNumberSeparators].Split('|');

The list is being read, but the carriage return ends up containing extra back slashes and looks like this - \\r\\n

Is there some way to prevent this from happening?

like image 943
A Bogus Avatar asked Feb 13 '23 06:02

A Bogus


1 Answers

You could try using XML entities &#10; and &#13;. Provided that the .NET configuration system supports resolving these entities, then these should appear as \r\n at runtime.

like image 160
Martin Costello Avatar answered Feb 16 '23 03:02

Martin Costello