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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With