简体   繁体   English

内置方法来获取字符串的C样式转义序列

[英]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.

相关问题 使用pInvoke将CW样式的LPWSTR数组编组为托管字符串[] - Marshalling C-style array of LPWSTR to managed string[] using pInvoke 从C#.NET调用带有C样式数组作为参数的C方法 - Calling a c-method with a c-style array as a parameter from C# .NET C#将包含c样式字符串的byte []转换为字符串 - NOT Encoding.GetString(byte []) - C# convert byte[] containing a c-style string to string - NOT Encoding.GetString(byte[]) C#中的C风格联盟 - C-Style Unions in C# 包括* /在C风格的块注释中 - Including */ in a C-style block comment VB中的多分配,如C风格的语言 - Multiassignment in VB like in C-Style languages 当通过C#调用C ++ DLL的导出类时,该类的C风格字符串成员在一个导出函数中是正常的,但在另一个导出函数中则没有 - When calling an exported class of a C++ DLL by C#, C-style string members of the class are OK in one exported function, but not in the other 为 C# 格式化 C 样式注释的设置 - Setting for formatting C-style comments for C# 如何围绕C风格的回调创建lambda-wrapper? - How to create lambda-wrapper around C-style callback? 如何有效地将 C 风格的函数(对于 Mono)绑定到 C++ 风格的类方法 - How to efficiently bind C-style function (for Mono) to C++ style class methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM