|
-
Jun 15th, 2005, 02:44 PM
#1
Thread Starter
Hyperactive Member
string
hi!
I am coding in c#
I have to put "abcd" in a string variable. Had it been abcd only I would have written
Code:
string str = "abcd";
str then wud have contained abcd.
but the problem is str has to contain "abcd".
Hope, I am clear in my post.
-
Jun 15th, 2005, 02:52 PM
#2
Re: string
like this ...
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]
hope it helps
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jun 16th, 2005, 12:16 AM
#3
Re: string
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.
-
Jun 16th, 2005, 07:29 AM
#4
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|