I am trying to persist string from an ASP.NET textarea. I need to strip out the carriage return line feeds and then break up whatever is left into a string array of 50 chara
Here is the perfect method:
Please note that Environment.NewLine works on on Microsoft platforms.
In addition to the above, you need to add \r and \n in a separate function!
Here is the code which will support whether you type on Linux, Windows, or Mac:
var stringTest = "\r Test\nThe Quick\r\n brown fox";
Console.WriteLine("Original is:");
Console.WriteLine(stringTest);
Console.WriteLine("-------------");
stringTest = stringTest.Trim().Replace("\r", string.Empty);
stringTest = stringTest.Trim().Replace("\n", string.Empty);
stringTest = stringTest.Replace(Environment.NewLine, string.Empty);
Console.WriteLine("Output is : ");
Console.WriteLine(stringTest);
Console.ReadLine();