zoukankan      html  css  js  c++  java
  • Char.IsDigit与Char.IsNumber的区别

    需要判断Char是否为数字,查看了下MSDN,发现有三种方法:

    Char.IsDigit (aChar)              指示指定字符串中位于指定位置处的字符是否属于十进制数字类别

    Char.IsNumber(aChar)        指示指定字符串中位于指定位置的字符是否属于数字类别

    aChar>='0'&&aChar<='9'     判断aChar是否位于‘0’到‘9’之前  等同于第一种

    用.NET Reflector 查看其实现代码:

    public static bool IsNumber(char c)  
    1. {  
    2.     if (!IsLatin1(c))  
    3.     {  
    4.         return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(c));  
    5.     }  
    6.     if (!IsAscii(c))  
    7.     {  
    8.         return CheckNumber(GetLatin1UnicodeCategory(c));  
    9.     }  
    10.     return ((c >= '0') && (c <= '9'));  
    11. }   
    public static bool IsDigit(char c)  
    1. {  
    2.     if (!IsLatin1(c))  
    3.     {  
    4.         return (CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber);  
    5.     }  
    6.     return ((c >= '0') && (c <= '9'));  
    7. }  

    Char.IsNumber 多了一步检查ASCII码。。。

  • 相关阅读:
    python numpy 介绍
    python+图像分割seg
    C++ 添加库
    input标签的disabled和readonly的区别
    linux中mysql忘记密码解决办法
    memcached服务安装与卸载
    app与服务端通信时如何进行消息校验
    缓存同步问题
    数据中添加对字段的说明
    服务器报警
  • 原文地址:https://www.cnblogs.com/micro-chen/p/11557919.html
Copyright © 2011-2022 走看看