I take from the text file the contents of the form:

Line 1 \ nLine 2 \ nLine 3 \ nLine 4 \ nLine 5

It is necessary to convert all control characters in a string like \ n , \ t to a newline and a tab, respectively, so that when this line is output to the screen
not this way:

Line 1 \ nLine 2 \ nLine 3 \ nLine 4 \ nLine 5

And so:

Line 1
Line 2
Line 3
Line 4
Line 5

Is it possible to implement this without resorting to the banal replacement of "\ n" by "\ n", "\ t" by "\ t"?

  • Specify what you are not satisfied with the "banal replacement" ? - Kromster
  • one
    string.Replace (@ "\ n", "\ n") works fine. What you are not satisfied with the replacement? - xxclojure
  • one
    Satisfied and replacement. But if the necessary function is already present, then why write it again? If it is not, then I will do exactly the replacement - svolex

1 answer 1

For this there are special methods in BCL, for example, Regex.Unescape :

 var s = @"Line 1\nLine 2\nLine 3\nLine 4\nLine 5"; Console.WriteLine(Regex.Unescape(s));