使用问题“”在C#中 [英] Problem For Using "" in C#

查看:67
本文介绍了使用问题“”在C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是C#的新手,希望在我的代码中使用String Variable。对于define String,我必须使用。

例如:string str =reza。

我的问题:

如果想要使用字符串这个字符串包含必须如何做?



例如:

string str =

Hi,
I am new in C# and want using String Variable in my code. For define String I must use "".
For example: string str="reza".
My question:
If want use string that this string is include "" how must do that?

For example:
string str=

"<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<p>Hi,</p>
<p>This is my first string.</p>
<p>Regards,</p>

</body>
";





问候,



Regards,

推荐答案

更改每个在你的字符串里面加一个 \(一个反斜杠后跟一个引号)。这是双引号的转义序列。

有关转义序列的更多信息: http://msdn.microsoft.com/en-us/library/h21280bw.aspx [ ^ ]



示例:

Change every " inside your string into a \" (a backslash followed by a quotation mark). This is the escape sequence for a double quotation mark.
More about escape sequences: http://msdn.microsoft.com/en-us/library/h21280bw.aspx[^]

Example:
string str = "In this string, an \"escape sequence\" is used";


你必须使用双引号或用斜杠分隔,如\在c#字符串中。



更好的选择是将文本作为资源嵌入并将其加载到字符串中。
You have to use double double quotes "" or delimit with a slash like \" in c# strings.

A better option is to embed your text as a resource and load it into your string.


2方式:



string str =在这个字符串中,使用\escape sequence \;(前面提到过)



替代方式:


string str = @在此字符串中,使用转义序列;
Two ways:

string str = "In this string, an \"escape sequence\" is used"; (Previously mentioned)

alternative way:

string str = @"In this string, an ""escape sequence"" is used";


这篇关于使用问题“”在C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆