简体   繁体   English

用 C# 中的实际字符替换转义字符

[英]Replace escaped characters with their actual characters in C#

I have a string of HTML content that looks like:我有一串 HTML 内容,如下所示:

<article aria-labelledby=\"aritcle-title-1\" class=\"col-md-12\">\n</article>    

I want to replace the escaped characters with their actual characters:我想用它们的实际字符替换转义字符:

Replace: \\n With: String.Empty替换:\\n 为:String.Empty

Replace: \\" With: "用。。。来代替: ”

I was using:我正在使用:

model.ContentHTML.Replace("\n", "");

But I can't figure out how to replace the escaped quote with an actual quote.但我不知道如何用实际报价替换转义的报价。 Any suggestions?有什么建议?

This should work:这应该有效:

model.ContentHTML.Replace("\\\"", "\"");

The first two backslashes resolve to a single backslash, and the \\" resolves to a "前两个反斜杠解析为单个反斜杠, \\"解析为"

You can also use Regex.Unescape() , if you're so inclined.如果您愿意,也可以使用Regex.Unescape()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM