我如何逃跑“在逐字符串中? [英] How do I escape " in verbatim string?
本文介绍了我如何逃跑“在逐字符串中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个常规的字符串,我使用了
\
逃避
,这里的转义意味着逃避编译器解释
,并获得
打印在屏幕上,我得到预期的输出 - > class Program
{
static void Main(string [] args)
{
string s1 =这是一个\regular \string;
System.Console.WriteLine (s1);
System.Console.Read();
}
}
o / p - >这是一个常规字符串
现在,我有一个逐字字符串,我试图逃避使用
\
以与上述相同的方式.-->
class Program
{
static void Main(string [] args)
{
string s2 = @这是\ ta \verbatim\string; //这将转义\t
System.Console.WriteLine(s2);
System.Console.Read();
}
}
为什么上述不起作用? >
解决方案
使用双引号:
string s2 = @这是\逐字string;
I am a bit new to c#, and i am stuck at this point,
I have a regular string, where i made use of \
to escape "
, escape here means that to escape the compilers interpretation of "
, and get "
printed on the screen, and i get the expected output-->
class Program
{
static void Main(string[] args)
{
string s1 = "This is a \"regular\" string";
System.Console.WriteLine(s1);
System.Console.Read();
}
}
o/p--> This is a "regular" string
Now, i have a verbatim string, and i am trying to escape "
using \
in the same manner as above..-->
class Program
{
static void Main(string[] args)
{
string s2 = @"This is \t a \"verbatim\" string";//this would escape \t
System.Console.WriteLine(s2);
System.Console.Read();
}
}
Why the above isn't working ?
解决方案
Use a double quote:
string s2 = @"This is \t a ""verbatim"" string";
这篇关于我如何逃跑“在逐字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文