Replacing double quote with a single quote
c#, replace
Solution
The reason
ptFirstName.Replace("\"", "'");
does not work is that `string` is immutable. You need to use
ptFirstName = ptFirstName.Replace("\"", "'");
instead. Here is a demo on ideone.
Problem
I have the following string in c#: ``` string ptFirstName = tboxFirstName.Text; ``` `ptFirstName` returns: `"John"` I wish to convert this to `'John'` I have tried numerous variations of the following, but I am never able to replace double quotes with single quotes: ``` ptFirstName.Replace("\"", "'"); ``` Can anybody enlighten me? My goal is to write this to an XML file: ``` writer.WriteAttributeString("first",ptFirstName); // where ptFirstName is 'John' in single quotes. ```