我有一个我不明白的问题。这是我的代码:
String input = "3 days ago"
String firstCharacter = input[0].ToString(); //Returns 3
int firstCharacter = (int)input[0]; //Returns 51
为什么返回51?
PS:我的代码来自此线程:C#:如何获取字符串的第一个字符?
更多信息:
In case that input = "5 days ago", then int firstCharacter is 53.
char
以int
这种方式强制转换为,将为您提供其ASCII值,其中3等于51。您可以在此处找到完整列表:
您想改为执行以下操作:
Char.GetNumericValue(input[0]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句