C# - 如何转义字符串转换成文本字符串? [英] C# - How can I convert an escaped string into a literal string?
问题描述
可能重复:结果
块引用> $ b $字符串b
的我能扩张>包含在运行C#的文字表达
如何转换在运行时,如:
<文件中读取一个转义字符串code>Line1\\\
Line2
到它的文本值:
1号线
2号线
令人惊讶,我发现一个例子做相反的这里使用CSharpCodeProvider(),这似乎将是更困难的转换。为了做到这一点似乎我需要生成代码来定义一个类,并在内存编译或执行一系列.Replace()的电话,希望我不会错过任何转义序列相反。
解决方案CSharpCodeProvider再次:)
看到答案的这里
有趣的是足够的 - 这问题问的问题给你链接到的相反:)
此外 - 理由基于它是一个重复的这个接近的选票
Possible Duplicate:
Can I expand a string that contains C# literal expressions at runtimeHow can I convert an escaped string read from a file at runtime, e.g.
"Line1\nLine2"
into its literal value:
Line1 Line2
Amazingly I have found an example to do the opposite here using CSharpCodeProvider(), which seems like it would be the more difficult conversion. In order to do the opposite it appears I need to generate code to define a class and compile it in memory or execute a series of .Replace() calls, hoping I don't miss any escape sequences.
解决方案CSharpCodeProvider again :)
See the answer here
Amusingly enough - that question asks for the opposite of the question to which you link :)
Also - grounds for a close vote for this based on it being a duplicate.
这篇关于C# - 如何转义字符串转换成文本字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!