Skip to content

Instantly share code, notes, and snippets.

@nshibano
Created June 10, 2020 14:39
Show Gist options
  • Save nshibano/88b9204ff8da66fe16a527cebf83d253 to your computer and use it in GitHub Desktop.
Save nshibano/88b9204ff8da66fe16a527cebf83d253 to your computer and use it in GitHub Desktop.
using System.Text;
namespace StringEscape
{
public static class StringEscape
{
public static string Escape(string input)
{
var sb = new StringBuilder();
//sb.Append("\"");
foreach (var c in input)
{
switch (c)
{
case '\t': sb.Append("\\t"); break;
case '\r': sb.Append("\\r"); break;
case '\n': sb.Append("\\n"); break;
default: sb.Append(c); break;
}
}
//sb.Append("\"");
return sb.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment