Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Format store double quotes inside string [duplicate]

Tags:

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.

like image 631
user1765862 Avatar asked Mar 25 '13 07:03

user1765862


People also ask

How do you handle double quotes in a string?

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.

How do you remove double quotes from a replacement string?

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.

How can you include a double quote character into a literal string?

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.


1 Answers

string.Format("{0}, {1}, \"{2}\", {3}, {4}, {5}", ...); 
like image 111
acrilige Avatar answered Sep 30 '22 13:09

acrilige