I'm trying to get some code in c# to check the start or end of a string and see if it has "\r\n" in one of these locations and if it does I want these characters removed. I do not want to remove these characters if they are not at the start or end though.
ex:
string tempStringA = "\r\n123\r\n456\r\n";
string tempStringB = "\r\n123\r\n456";
string tempStringC = "123\r\n456\r\n";
tempStringA, tempStringB, and tempStringC would all become "123\r\n456"
Regex.Replace(s, @"\A\r\n(.*)\r\n\z", RegexOptions.Singleline). A non-regex way is still preferred:if (s.EndsWith("\r\n") && s.StartsWith("\r\n")) s = s.Substring(1, s.Length-2)