简体   繁体   English

如何在字符串或字符中声明 ^\

[英]How can i declare ^\ in a string or character

I would like to declare ^\ this as a string or character.我想将^\ this 声明为字符串或字符。 I used the below but i am getting an error我使用了以下内容,但出现错误

 string str="^\";

So can any one help me所以任何人都可以帮助我

You have to escape the backslash.你必须逃避反斜杠。

string str = "^\\";

Or, you can use the verbatim syntax.或者,您可以使用逐字语法。

string str = @"^\";

\ is the escape token, you have to double it to use it as a literal in a string: \是转义标记,您必须将其加倍才能将其用作字符串中的文字:

string str = "^\\";

Alternatively, you can use literal string syntax:或者,您可以使用文字字符串语法:

string str = @"^\";

You need to escape backslash characters, so instead of:您需要转义反斜杠字符,而不是:

string str = "^\";

use:利用:

string str = "^\\";

I have no idea about C#, but can you try:我不知道 C#,但你可以试试:

string str="^\\";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM