Strin in Quotation marks

  • Thread starter Thread starter David
  • Start date Start date
D

David

Is there any function for including string in single or double quotation
marks?
For example I have string SOMESTRING and I want to get 'SOMESTRING' or
"SOMESTRING"
 
David said:
Is there any function for including string in single or double quotation
marks?
For example I have string SOMESTRING and I want to get 'SOMESTRING' or
"SOMESTRING"

string original = "SOMESTRING";
string inSingleQuotes = "'"+original+"'";
string inDoubleQuotes = "\""+original+"\"";
 
Yes, but there is no any function for this?

Jon Skeet said:
string original = "SOMESTRING";
string inSingleQuotes = "'"+original+"'";
string inDoubleQuotes = "\""+original+"\"";
 
David said:
Yes, but there is no any function for this?

Not in the framework, no. It's hardly hard to write one yourself
though:

static string DoubleQuote (string original)
{
return "\""+original+"\"";
}

static string SingleQuote (string original)
{
return "\""+original+"\"";
}

Alternatively:

static string Wrap(string original, char c)
{
return c+original+c;
}

called like:

string foo = Wrap("hello", '\"');
or
string foo = Wrap("hello", '\'');
 
Back
Top