Is there a standard library method in .Net that will programmatically escape a character? That is, take as input e.g. '\n'
(the newline character) and return a string containing two characters, the first of which is a backslash and the second of which is a lowercase N? (Regex.Escape seems to do the reverse.)
Asked
Active
Viewed 61 times
0

rwallace
- 31,405
- 40
- 123
- 242
-
1Are you sure Regex.Escape isn't what you want? I'm seeing `Regex.Escape("\n")` produce `"\\n"`(a 2 character string). – Joe Sewell Mar 23 '20 at 15:11
-
1See : https://stackoverflow.com/questions/323640/can-i-convert-a-c-sharp-string-value-to-an-escaped-string-literal - it works on a string, but shouldn't be a problem to convert to using a char. – PaulF Mar 23 '20 at 15:13
-
@JoeSewell Ah, you are quite correct, if you convert the input character to a string first, then it does the job. Thanks! – rwallace Mar 23 '20 at 15:15