我找到了这个:
private static string ToLiteral(string input){ using (var writer = new StringWriter()) { using (var provider = CodeDomProvider.CreateProvider("CSharp")) { provider.GenerateCodeFromexpression(new CodePrimitiveexpression(input), writer, null); return writer.ToString(); } }}
这段代码:
var input = "tHellorntWorld!";Console.WriteLine(input);Console.WriteLine(ToLiteral(input));
产生:
Hello World!"tHellorntWorld!"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)