yaosansi's Blog

当你背向太阳的时候,你只会看到自己的阴影!能力是有限的,努力无限的!

导航

C#(IsNumeric) 字符串转换为数字

判断C#中的字符串是否是数字,如果是转换成int类型(可以判断正数和负数)
1public int IsNumeric(string str)
2
3int i;
4if(str != null && System.Text.RegularExpressions.Regex.IsMatch(str,@"^-?\d+$"))
5= int.Parse(str);
6else
7= -1;
8return i;
9}
 

posted on 2005-10-25 10:50  yaosansi  阅读(1244)  评论(0编辑  收藏  举报