C # Replacing Shielded Screens

Ive parsed the text file in the List<string> object and the test file contains \n and \t , however, as soon as I output the lines to the console, they are displayed as "\ n" and "\ t", not a new line and tab .

I am currently using myList[i].Replace(@"\n", "\n").Replace(@"\t", "\t") , but this seems a bit cumbersome, especially if you need to add in the future extra escape sequences.

Do they have any way to avoid escape sequences? Something like string.UnEscape would be just perfect.

+4
source share
2 answers

I'm not sure if this will do exactly what you need, but there is a Unescape method in RegEx Namespace.

 string result = Regex.Unescape(myList[i]); 
+1
source

You can write your own helper.

  public static class Helper { public static string Unescape(this string val) { return val.Replace(@"\n", "\n").Replace(@"\t", "\t"); } } 
+3
source

Source: https://habr.com/ru/post/1379295/


All Articles