hi!
I am coding in c#
I have to put "abcd" in a string variable. Had it been abcd only I would have written
str then wud have contained abcd.Code:string str = "abcd";
but the problem is str has to contain "abcd".
Hope, I am clear in my post.
Printable View
hi!
I am coding in c#
I have to put "abcd" in a string variable. Had it been abcd only I would have written
str then wud have contained abcd.Code:string str = "abcd";
but the problem is str has to contain "abcd".
Hope, I am clear in my post.
like this ...
hope it helps :wave:VB Code:
[COLOR=Blue]string[/COLOR] str = @"""abcd"""; Console.WriteLine(str); [COLOR=Green] // outputs "abcd" ( including the " ) // if you want the . at the end ... string str = @"""abcd""."; [/COLOR]
In C# you can escape any single character with a '\' character so you could use
string str = "\"abcd\"";
Preceeding a string with an '@' character tells the compiler to take the entire string as literal. That means that @"\n" is not a new-line character but actually a string that contains the characters '\' and 'n'. In the case of double quotes, as dynamic_sysop shows, you still have to escape them with another double quote to show that they are not a string delimiter.
Thanks a bunch.