Reputation: 201
I'm using String.Replace to replace certain characters. How do I replace the " sign with a different sign of my choice?
artikelBezeichnung = artikelBezeichnung.Replace(""", "!");
That doesn't seem to work
Upvotes: 2
Views: 1443
Reputation: 1214
Using ASCII
artikelBezeichnung = artikelBezeichnung.Replace(Char.ConvertFromUtf32(34), "!");
Upvotes: 1
Reputation: 54
string stringContainingContent = "fsdfsfsdfsdfsdfsdfsdfsf\"sdfsdfsdffsd";
string test = "\"";
string test1 = stringContainingContent.Replace(test, "!");
You can replace using Skip Sequence.
Upvotes: 1
Reputation: 31857
The quote is an special char in C#. You need use it as an string literal, You need to scape it:
Using slash:
artikelBezeichnung = artikelBezeichnung.Replace("\"", "!");
Or using @:
artikelBezeichnung = artikelBezeichnung.Replace(@"""", "!");
Upvotes: 1
Reputation:
Escaping isn't really necessary, since String.Replace
has an overload that accepts a char
:
artikelBezeichnung = artikelBezeichnung.Replace('"', '!');
Upvotes: 5
Reputation: 28272
Either:
artikelBezeichnung = artikelBezeichnung.Replace("\"", "!");
Or:
artikelBezeichnung = artikelBezeichnung.Replace(@"""", "!");
Upvotes: 10
Reputation: 2546
You have to add a backslash.
artikelBezeichnung = artikelBezeichnung.Replace("\"", "!");
or adding the @ symbol
artikelBezeichnung = artikelBezeichnung.Replace(@"""", "!");
Upvotes: 1