Link to home
Start Free TrialLog in
Avatar of trevor1940
trevor1940

asked on

C# How to handle double quotes in string replace

Hi

How do I replace '\"' with '"' globally in C#
Backslash  Double Quotes replace with Double Quotes
and remove Double Quotes from the end of a string

string MyString = "Lorem \"ipsum\" dolor sit amet \"consectetuer\" ultrices turpis Phasellus et odio. Urna."";
MyString.Replace('\\"', '"'); // Error CS1012  C# Too many characters in character literal
MyString.Replace("\\"", "\""); didn't work

Console.WriteLine(MyString);
// Expected output
Lorem "ipsum" dolor sit amet "consectetuer" ultrices turpis Phasellus et odio. Urna.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trevor1940
trevor1940

ASKER

Hi
Thank you the regex was what I needed

What I'm trying to do is clean up up some badly formed  HTML so I can parse it using HtmlAgilityPack;

Replacing the
\"
was an obvious quick fix

The code I posted was only to try and illustrate the point
I used the regex  but can Chris solution also working
FYI
For some reason the whole HTML file / string was in Double Quote marks so I had to remove these from the first and last characters then remove the internal \ backslashes