I have an application that is sensitive to a carriage return being \r\n or \n. I'm passing around a value in XML and when I parse it using XDocument the carriage retrun value is being converted to \n and I'm trying to find a way to keep it preserved as \r\n.
string myVal = "1234\r\nabcd";
string xmlText = "<doc>" + myVal + "</doc>";
XDocument xDoc = XDocument.Parse(xmlText);
Console.WriteLine("result=" + (xDoc.Element("doc").Value == myVal));
Console.WriteLine("result=" + (xDoc.Element("doc").Value == myVal.Replace("\r\n", "\n")));
Results:
result=False
result=True