繁体   English   中英

C#字符串长度

[英]C# String Length

为什么这两个字符串返回不同的长度值。 “CertificateKey”是一个属性。 它的长度为41。 但是,等效常量字符串返回40.如果我将证书的值复制为常量,则长度返回41.为什么?!?

// This is the property. Length 41
CertificateKey.Length

41

// This is a constant of the same string. Length 40
"9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384".Length

40

// This is a copy of the value of the property above. Length 41
"‎9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384".Length

41

我将你的两个字符串文字复制并粘贴到LINQPad中 ,发现我可以重现你的结果,然后我就像这样打印每个字符:

var a = "9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384";
var b = "‎9FE90CA8A4138F65E9E2C67D1F37B9D5B9919384";
foreach (char c in a) Console.WriteLine($"{(int)c:X}");
Console.WriteLine("---");
foreach (char c in b) Console.WriteLine($"{(int)c:X}");

得到以下结果:

39
46
[...]
34
---
200E
39
46
[...]
34

200E从左到右的标记

暂无
暂无

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

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