问题描述
C#中Char.IsDigit()
和Char.IsNumber()
有什么区别?
推荐答案
Char.IsDigit()
是 Char.IsNumber()
的子集.
一些数字"但不是数字的字符包括 0x00b2 和 0x00b3,它们是上标 2 和 3(²"和³")以及作为分数的字形,例如¼"、½",和'¾'.
Some of the characters that are 'numeric' but not digits include 0x00b2 and 0x00b3 which are superscripted 2 and 3 ('²' and '³') and the glyphs that are fractions such as '¼', '½', and '¾'.
请注意,IsDigit()
返回true
的字符很多,因为它们不在 0x30 到 0x39 的 ASCII 范围内,例如这些泰语数字字符: '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'.
Note that there are quite a few characters that IsDigit()
returns true
for that are not in the ASCII range of 0x30 to 0x39, such as these Thai digit characters: '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'.
这段代码告诉您哪些代码点不同:
This snippet of code tells you which code points differ:
static private void test()
{
for (int i = 0; i <= 0xffff; ++i)
{
char c = (char) i;
if (Char.IsDigit( c) != Char.IsNumber( c)) {
Console.WriteLine( "Char value {0:x} IsDigit() = {1}, IsNumber() = {2}", i, Char.IsDigit( c), Char.IsNumber( c));
}
}
}
这篇关于C#中Char.IsDigit()和Char.IsNumber()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!