Formatting an XML Value in a string

Hey all,

So I’m reading an XML Value from a file - a string value that says something like “Hello World. How are you?”

In the xml file, I’ve written it as “Hellow World. \n How are you?”

This was in the hopes that when I return it as a string, it would display as two line s- but right now it just returns it as is. Is there an easy way I can take this string and apply the formatting properly so it outputs as:

Hello World.
How are you?

Thanks in advance!

XML doesn’t process escape sequences (most likely for security reasons) so your string is effectively being loaded as “Hellow World. \n How are you?”. You can fix this by replacing the “\n” with Environment.NewLine after loading the string.

string xmlString = "Hellow World. \\n How are you?";
xmlString = xmlString.Replace("\\n", Environment.NewLine);
1 Like

Ohhh that explains it, I tried Replace but was calling it for \n.

Thanks much!