开发者

How to create a string with special characters in C#

How can I create a string whic开发者_开发问答h contains the following:

<Object type="System.Windows.Forms.Form


Use an escape character for the quote:

string temp = "<Object type=\"System.Windows.Forms.Form"

See the msdn article for more examples: http://msdn.microsoft.com/en-us/library/h21280bw.aspx

Edit

Correct link for C#: C# programming guide


You have two choices, depending on the remainder of the text you want to place into the string:

use the escape character \ within the double-quoted string for any double-quote marks, as the other answers have suggested.

string s = "<Object type=\"System.Windows.Forms.Form";

use the string-@ form, which avoids processing the \ (such as in path names like C:\Temp\Myfile.txt), and then double the double-quote:

string s = @"<Object type=""System.Windows.Forms.Form";

See also: http://msdn.microsoft.com/en-us/library/362314fe(v=vs.71).aspx


You can use the backslash character to escape strings, the example below should fit your needs:

Example:

string test = "<Object type=\"System.Windows.Forms.Form";

MSDN Specification on String Literals / Escaping Literals:

MSDN : String Literals


string s = "<Object type=\"System.Windows.Forms.Form";

Is that what you mean?


var str = "<Object type=\"System.Windows.Forms.Form";


Use backslash to escape.

String str = "<Object type=\"System.Windows.Forms.Forms";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜