I have the following format var format = "0\"";
I then use it like this 1.ToString(format);
I'm expecting it to return 1"
but it returns 1
How do I make it insert the double quote ("
)?
I have tried...
var format = "0\u0022";
var format = @"0""";
and can't get it to work.
It does work if I use string.Format
...
var format = "{0}\"";
string.Format(format, 1)
that will give me 1"
as required.
Does anyone know how to get .ToString()
method to insert the double quote?
When you want to add characters into format string as the they are (not as a part of the format string), wrap them into apostrophes '...'
:
// 0 - specifies format
// '\"' - will be preserved as it is - "
string result = 1.ToString("0'\"'");
Console.Write(result);
Outcome:
1"
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