Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace straight quotation mark (")

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

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

someWord.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?

like image 374
Willem Avatar asked Oct 28 '11 04:10

Willem


People also ask

How do you force straight quotation marks?

The key that appear on your keyboard (near the return key) generates straight quotation marks with a single or double vertical lines.

Why are my quotation marks straight?

Straight quotation marks were introduced on typewriters to reduce the number of keys on the keyboard, and they were retained for computer keyboards and character sets.


2 Answers

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("\"", """);

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

someWord = HttpUtility.HtmlEncode(someWord);

like image 92
ojlovecd Avatar answered Oct 03 '22 17:10

ojlovecd


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

or

someWord.Replace(@"""", "&");

(Quotes are escaped as \" in regular strings and "" in verbatim strings.)

But you probably meant

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

since the HTML entity for straight quotation marks is ", not &.

like image 45
Heinzi Avatar answered Oct 03 '22 18:10

Heinzi