您的位置:首页 > 编程语言 > C#

C#中如何判斷一個String是否為數字

2007-04-10 16:42 555 查看
Copied From /article/6912989.html
方案一:TryCatch(执行效率不高)
private bool IsNumberic(string oText)

方案二:正则表达式(推荐)
a)
using System;
using System.Text.RegularExpressions;

public bool IsNumber(String strNumber)

b)
public static bool IsNumeric(string value)
public static bool IsInt(string value)
public static bool IsUnsign(string value)

方案三:遍历
a)
public bool isnumeric(string str)

b)

c)
public static bool isNumeric(string inString)

方案四:改写vb的IsNumeric源代码(执行效率不高)

//主调函数
public static bool IsNumeric(object Expression)

//子函数
// return Utils.IsNumericTypeCode(code1);
internal static bool IsNumericTypeCode(TypeCode TypCode)

//-----------------
//StringType.IsHexOrOctValue(text1, ref num2))
internal static bool IsHexOrOctValue(string Value, ref long i64Value)
//----------------------------------------------------
// DoubleType.TryParse(text1, ref num1);
internal static bool TryParse(string Value, ref double Result)

方案五: 直接引用vb运行库(执行效率不高)

方法: 首先需要添加Visualbasic.runtime的引用
代码中Using Microsoft.visualbasic;
程序中用Information.isnumeric("ddddd");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: