C#判断字符串是否是数字字符串

    xiaoxiao2026-06-18  3

    第一种方法 使用Try Catch(不推荐)

    private bool IsNumberic(string oText) { try { int var1=Convert.ToInt32 (oText); return true; } catch { return false; } }

    第二种方法 正则表达式(推荐)

    public static bool IsNumeric(string value) { return Regex.IsMatch(value, @"^[+-]?/d*[.]?/d*$"); } public static bool IsInt(string value) { return Regex.IsMatch(value, @"^[+-]?/d*$"); } public static bool IsUnsign(string value) { return Regex.IsMatch(value, @"^/d*[.]?/d*$"); }

    第三种方法 遍历(显得很弱)

    转载请注明原文地址: https://ju.6miu.com/read-1310650.html
    最新回复(0)