[英]Why/how function string.Substring treats "\u0002" as a one sign? Unicode chars in C#
Why/how function string.Substring treats "\" as a one sign?为什么/如何函数string.Substring将“\”视为一个符号? I mean ok, "\" is a "character" STX.
我的意思是,“\”是一个“字符”STX。
Code checks if preffix suffics is correct.代码检查前缀是否正确。 Data length does not matter.
数据长度无关紧要。 Prefix is STX , suffix is ETX added do data string.
前缀是 STX ,后缀是 ETX 添加的数据字符串。 How to do this(code below) explicitly without a doubt?
毫无疑问,如何明确地做到这一点(下面的代码)?
string stx = "\u0002";
string etx = "\u0003";
string ReceivedData= stx + "1122334455" + etx;
string prefix = ReceivedData.Substring(0, 1);
string suffix = ReceivedData.Substring(ReceivedData.Length - 1, 1);
Do you wonder the working mechanism of UTF-16 and Unicode?你想知道 UTF-16 和 Unicode 的工作机制吗? May this topic helps: What is Unicode, UTF-8, UTF-16?
本主题可能会有所帮助: 什么是 Unicode、UTF-8、UTF-16?
The code snippet looks reasonable as the variables are explicitly named and '\\u\u0026#39; is a sign of Unicode.代码片段看起来很合理,因为变量被显式命名并且 '\\u\u0026#39; 是 Unicode 的标志。
string stx = "\u0002";
string etx = "\u0003";
string prefix = ReceivedData.Substring(0, 1);
string suffix = ReceivedData.Substring(ReceivedData.Length - 1, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.