asp.net 判断字符串是否是数字的,int的,整型的

  1. #region 判断字符串是否是数字的
  2. /// <summary>
  3. /// 判断是否是数字
  4. /// </summary>
  5. /// <param name="str">字符串</param>
  6. /// <returns>bool</returns>
  7. publicbool IsNumeric(string str)
  8. {
  9. if (str == null || str.Length == 0)
  10. returnfalse;
  11. System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
  12. byte[] bytestr = ascii.GetBytes(str);
  13. foreach (byte c in bytestr)
  14. {
  15. if (c < 48 || c > 57)
  16. {
  17. returnfalse;
  18. }
  19. }
  20. returntrue;
  21. }