AzulShiva
AzulShiva

Reputation: 201

C# Putting a quotation mark within quotation marks?

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

Answers (6)

Lewis Hai
Lewis Hai

Reputation: 1214

Using ASCII

artikelBezeichnung = artikelBezeichnung.Replace(Char.ConvertFromUtf32(34), "!");

Upvotes: 1

Mahesh Patidar
Mahesh Patidar

Reputation: 54

string stringContainingContent = "fsdfsfsdfsdfsdfsdfsdfsf\"sdfsdfsdffsd";
            string test = "\"";
            string test1 = stringContainingContent.Replace(test, "!");

You can replace using Skip Sequence.

Upvotes: 1

Daniel Peñalba
Daniel Peñalba

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

user1726343
user1726343

Reputation:

Escaping isn't really necessary, since String.Replace has an overload that accepts a char:

artikelBezeichnung = artikelBezeichnung.Replace('"', '!');

Upvotes: 5

Jcl
Jcl

Reputation: 28272

Either:

artikelBezeichnung = artikelBezeichnung.Replace("\"", "!");

Or:

artikelBezeichnung = artikelBezeichnung.Replace(@"""", "!");

Upvotes: 10

Galma88
Galma88

Reputation: 2546

You have to add a backslash.

artikelBezeichnung = artikelBezeichnung.Replace("\"", "!");

or adding the @ symbol

artikelBezeichnung = artikelBezeichnung.Replace(@"""", "!");

Upvotes: 1

Related Questions