[英]Built in method to get C-style escaped sequence for a string
Is there a built method in .Net for C-style escaping of strings? .Net中是否有用于C样式转义字符串的内置方法?
For example, I have to convert a string which contains quotes like "hello"
, and write it as an escaped string \\"hello\\"
. 例如,我必须转换一个包含诸如"hello"
类的引号的字符串,并将其写为转义字符串\\"hello\\"
。
Actually, to be more precise: 实际上,更确切地说:
string original = "\"hello\"";
should be converted to 应该转换为
string what_i_need = "\\\"hello\\\"";
I could have probably done it myself while writing this question, but I don't want to reinvent hot water. 在写这个问题时,我本来可以做到的,但是我不想重新发明热水。
[Edit] According to the provided answer, this is actually a duplicate of : Can I convert a C# string value to a string literal . [编辑]根据提供的答案,这实际上是以下内容的重复 : 我可以将C#字符串值转换为字符串文字 。 It didn't pop out since there were no tags and keywords I was looking for. 它没有弹出,因为我没有寻找的标签和关键字。
I dont think there is any built in methods. 我不认为有任何内置方法。 But if you have to write your own, Can I convert a C# string value to a string literal post maybe helpful 但是,如果您必须编写自己的代码, 我可以将C#字符串值转换为字符串文字帖子可能会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.