Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. string replaced = original.Replace("\n", "n");
  2.  
  3. string EscapeLikeALiteral (string src) {
  4. return Regex.Replace(src, @"\(?<simple>['""\0abfnrtv])", (m) => {
  5. var s = m.Groups["simple"].Value;
  6. switch (s) {
  7. case "'": return "'";
  8. case """: return """;
  9. case "0": return "";
  10. case "a": return "a";
  11. case "b": return "b";
  12. case "f": return "f";
  13. case "n": return "n";
  14. case "r": return "r";
  15. case "t": return "t";
  16. case "v": return "v";
  17. default:
  18. throw new InvalidOperationException();
  19. }
  20. });
  21. }
  22.  
  23. var r = EscapeLikeALiteral(@"hellonworld");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement