UTF-16错误,无法识别的转义序列如何解决?
UTF-16 error, how to solve the unrecognized escape sequence?
This program is a translator program that takes some symbols and converts them to normal letters.
The problem is, when I try to put some symbols like: allAlphabets.Add("[]/[]"); or: allAlphabets.Add("//"); , i get an error about the UTF-16
static void Main(string[] args)
{
string input = ""; // string input
List<string> allAlphabets = new List<string>(); // storing to a list
input = Console.ReadLine();
char[] word = input.ToCharArray();
for (int i = 0; i < word.Length; i++)
{
switch (word[i]) // switch casce
{
normal letters
case 'm':
allAlphabets.Add("[]\/[]"); // represents text as a sequence of utf-16 code units
break;
case 'n':
allAlphabets.Add("[]\[]"); // represents text as a sequence of utf-16 code units
case 'v':
allAlphabets.Add("\/"); // represents text as a sequence of utf-16 code units
break;
case 'w':
allAlphabets.Add("\/\/"); // represents text as a sequence of utf-16 code units
}
}
}
}
Does someone know a way of encoding the unrecognized escape sequence?
Thank you!
您需要使用 verbatim identifier (@
)
To indicate that a string literal is to be interpreted verbatim. The @
character in this instance defines a verbatim string literal. Simple
escape sequences (such as "\"
for a backslash), hexadecimal escape
sequences (such as "\x0041"
for an uppercase A), and Unicode escape
sequences (such as "\u0041"
for an uppercase A) are interpreted
literally. Only a quote escape sequence (""
) is not interpreted
literally; it produces a single quotation mark. Additionally, in case
of a verbatim interpolated string brace escape sequences ({{
and }}
)
are not interpreted literally; they produce single brace characters.
allAlphabets.Add(@"[]\/[]");
或转义反斜杠
allAlphabets.Add("[]\/[]")
其他资源
This program is a translator program that takes some symbols and converts them to normal letters. The problem is, when I try to put some symbols like: allAlphabets.Add("[]/[]"); or: allAlphabets.Add("//"); , i get an error about the UTF-16
static void Main(string[] args)
{
string input = ""; // string input
List<string> allAlphabets = new List<string>(); // storing to a list
input = Console.ReadLine();
char[] word = input.ToCharArray();
for (int i = 0; i < word.Length; i++)
{
switch (word[i]) // switch casce
{
normal letters
case 'm':
allAlphabets.Add("[]\/[]"); // represents text as a sequence of utf-16 code units
break;
case 'n':
allAlphabets.Add("[]\[]"); // represents text as a sequence of utf-16 code units
case 'v':
allAlphabets.Add("\/"); // represents text as a sequence of utf-16 code units
break;
case 'w':
allAlphabets.Add("\/\/"); // represents text as a sequence of utf-16 code units
}
}
}
}
Does someone know a way of encoding the unrecognized escape sequence? Thank you!
您需要使用 verbatim identifier (@
)
To indicate that a string literal is to be interpreted verbatim. The
@
character in this instance defines a verbatim string literal. Simple escape sequences (such as"\"
for a backslash), hexadecimal escape sequences (such as"\x0041"
for an uppercase A), and Unicode escape sequences (such as"\u0041"
for an uppercase A) are interpreted literally. Only a quote escape sequence (""
) is not interpreted literally; it produces a single quotation mark. Additionally, in case of a verbatim interpolated string brace escape sequences ({{
and}}
) are not interpreted literally; they produce single brace characters.
allAlphabets.Add(@"[]\/[]");
或转义反斜杠
allAlphabets.Add("[]\/[]")
其他资源