How to represent a quote within a string in C#

Hi

A very common problem people come-up with while working with string data type is how to work with special character. A number of characters have been labeled as special characters. How would you represent a quote within a string, since the compiler interprets a quote as the beginning or end of the string? Whenever you want to use one of these special characters you need to use a technique known as escaping the character.

Here is a list of the string that needs to be used for the purpose of this special character.

\n = New Line
\r = Carriage return
\r\n = Carriage return and New line
\” = Quotation mark
\\ = Backlash character
\t = Tab

[Note: Even though escaped characters involve two characters (backslash \ plus the escaped character) the compiler treats the sequence as one character. That means that \n is a single character and the same is true for \", \\, etc]

Hope this helps
Thanks
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 10/13/2007 2:12:42 PM

write in textBox1.Text alabala ' xyz " 1 23
string s=textBox1.Text;
convert s to alabala \' \"123 if you can in C sharp.

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia