Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Label ignoring new lines ("\n") coming from the App.config file?

Tags:

c#

.net

winforms

So I have an App.config file setup something like this:

<configuration>
    <appSettings>
        <add key="Description" value="My too long of a\n description that needs\n new lines so the entire\n thing can be seen."/>
    </appSettings>
</configuration>

Now, at run-time, I need to change the Text property of a Label to one of these many descriptions located in the App.config file. If I include the new line character in the App.config, the Label seems to ignore that it is a new line character and instead prints it out literally. However, if I were to remove these new line characters and insert them at run-time, then the Label will recognize them and insert new lines as it should.

My question is, why? Why does the Label ignore them and print them out literally if they come from the App.config?

To use this description from the App.config, this is all I'm doing:

myLabel.Text = ConfigurationManager.AppSettings["Description"];
like image 258
Ricky L. Avatar asked Sep 20 '25 23:09

Ricky L.


1 Answers

I would expect \r\n (return, newline) on a Windows system, not just newline. In any case, App.config is XML, so you want the XML escape sequences:

&#xD;&#xA;
like image 174
Joe Avatar answered Sep 22 '25 12:09

Joe