Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Replace not replacing apostrophe

Tags:

string

c#

replace

I'm trying to replace apostrophes with a string, for some reason the method just doesn't find the apostrophe in the string. Here is the URL that just doesn't seem to work:

"/news/2012/march/cameron’s-crackdown-on-whiplash-–-why-the-minimum-speed-requirement-is-oddly-suspicious"
.Replace("'", "'");

Does anyone have any ideas?

like image 863
Funky Avatar asked Nov 30 '22 04:11

Funky


2 Answers

The replace doesn't work because and ' are not the same character.

And maybe you forgot to capture the result, your code is too short to tell.

like image 120
Henk Holterman Avatar answered Dec 04 '22 02:12

Henk Holterman


and ' are different characters. You also need to assign it somewhere (strings are immutable), Replace() returns new string:

myString = myString.Replace("’", "'");
like image 24
Zbigniew Avatar answered Dec 04 '22 03:12

Zbigniew