public bool isnumeric( string str) { char[] ch=new char[str.Length]; ch=str.ToCharArray(); for(int i=0;i<ch.Length;i++) { if(ch[i]<48 || ch[i]>57) return false; } return true; } public string coder( string source) { if(source!=string.Empty&&source!=null) { source =source.Replace("<","<<"); source=source.Replace(">",">>"); source= source.Replace("\r\n", "<br/>"); source= source.Replace("\n", "<br/>"); source = source.Replace(" ", " "); return source; } else{ return source; } } public bool IsNumeric( string s, out double result) { bool bReturn = true; try { result = double.Parse(s); } catch { result = 0; bReturn = false; } return bReturn; } public int IsNumeric( string str) { int i; if(str != null && Regex.IsMatch(str,@"^\d+$")) i = int.Parse(str); else i = -1; return i; } 转载于:https://www.cnblogs.com/oosumu/archive/2005/01/12/90891.html