Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static string EscapeChars(string Input)
- {
- string Output = "";
- char lastChar = '0';
- foreach (char c in Input)
- {
- if (lastChar == '\\')
- {
- switch (c)
- {
- case 'n':
- case 'r':
- case 't':
- Output += @"\" + c;
- break;
- }
- }
- else
- {
- Output += c;
- }
- lastChar = c;
- }
- return Output;
- }
- static void Main(string[] args)
- {
- string escaped = EscapeChars("Hello \n\r");
- Console.WriteLine(escaped); //Prints "Hello" followed by two newlines.
- Console.WriteLine(escaped == "Hello \n\r"); //Prints "true" -- no conversion was done.
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement