本文介绍了如何替换直引号(")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更换一个直引号使用C#()。

I would like to replace a straight quotation mark (") using C#.

我可能失去了一些东西小,但我不能用正常的得到它与string.replace();

I might be missing something small, but I can't get it with a normal string.Replace();

someWord.Replace(@ &放大器;放大器;);

我可以用普通的与string.replace()做到这一点; 或者我需要使用正则表达式?如果是后者,你会在正则表达式更换样子?

Can I do it with a normal string.Replace(); or do I need to use Regex? If the latter, what would the Regex replace look like?

推荐答案

我同意Heinzi,你应该使用&放大器; QUOT; 而不是&放大器;放大器; &放大器;放大器; 表示&放大器;
顺便说一句,调用替换方法后,别忘了再将该值设置为someWord:

I agree with Heinzi, you should use " instead of &, and & means "&"Btw, after invoking the Replace method, don't forget to set the value to someWord again:

someWord = someWord.Replace("\"", """);

和有另一种方式来做到这一点添加引用System.Web程序,以及使用的System.Web;
,则:

And there is another way to do it. Add the reference System.Web, and using System.Web;then:

someWord = HttpUtility.HtmlEncode(someWord);

someWord = HttpUtility.HtmlEncode(someWord);

这篇关于如何替换直引号(")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:58