I want to represent the following string:
aaaa,23,"something inside double quotes", 99, 8, 7
I was thinking to do this using String.Format
:
StringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}", item.one, item.two, item.three, item.four, item.five, item.six));
I need to wrap third argument {2}
with double quotes.
If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.
Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.
To represent a double quotation mark in a string literal, use the escape sequence \". The single quotation mark (') can be represented without an escape sequence. The backslash (\) must be followed with a second backslash (\\) when it appears within a string.
string.Format("{0}, {1}, \"{2}\", {3}, {4}, {5}", ...);
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