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");
方案一: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");
相关文章推荐
- C#中String如何判断是否为空
- 如何判斷一個查詢結果是否為空?
- (原創) 如何判斷一個字串是否存在於另外一個字串? (C/C++) (C)
- C#检查一个字符串是否为空要用STRING.LENGTH
- C#判断一个string是否可以为数字
- [C#] 如何将String类型转换成任意基本类型
- C#判断一个string是否可以为数字...
- C#判断一个string是否为数字
- C#判断一个String是否为数字类型
- C#.NET常见问题(FAQ)-如何捕捉窗体关闭的事件,弹窗确认是否退出
- C# webclient UploadStringAsync如何得到变量?
- c# .net 如何把byte类型仅仅转换成string而不改变其内容
- C#中如何判断当前线程是否为主线程
- C# 如何判断指定文件是否正被其它程序使用
- Delphi的dll如何向C#传出string(2)
- 如何判断字符串是否为空串?[C#]
- 由浅入深CIL系列:5.抛砖引玉:判断string是否为空的四种方法的CIL代码看看效率如何?
- C#判断一个string是否可以为数字,五种解决方案
- C#.NET常见问题(FAQ)-如何判断某个字符是否为汉字
- 如何用C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?