在C#中Char.IsDigit()和Char.IsNumber()之间的区别 [英] Difference between Char.IsDigit() and Char.IsNumber() in C#
问题描述
什么的区别 Char.IsDigit()
和 Char.IsNumber()
在C#?
推荐答案
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()
返回真
对于不在ASCII范围的0x30至0x39,如这些泰数字字符:0123456'7''8''9'
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: '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'.
的code这个片段告诉你哪个code点不同:
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()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!