Java judging numbers or Chinese or letters

Source: Internet
Author: User
Tags chr

1. Determine if the string is only a numeric:1> with Java-brought function public static boolean isnumeric (string str) {  for   (Int i = str.length ();--i>=0;) {      if  (! Character.isdigit (Str.charat (i))) {    return false;   }  }   return true; }2> Regular Expression public static boolean isnumeric (STRING&NBSP;STR) {    pattern pattern = pattern.compile ("[0-9]*");     Return pattern.matcher (str). Matches ();    }3> with ASCII code public static  Boolean isnumeric (STRING&NBSP;STR) {   for (Int i=str.length ();--i>=0;) {       int chr=str.charat (i);       if (chr<48 | |  chr>57)          return false;   }    return true;} &Nbsp; 2. Determines whether the first character of a string is a letter public   static   boolean   test ( String   s)      {     char   c    =   s.charat (0);     int   i    = (int) c;     if ((i>=65&&i<=90) | | (i>=97&&i<=122))      {     return   true;      }     else     {      Return   false;     }     }  public      static   boolean   check (String    Fstrdata)              {       &nbsP;              char   c    =   fstrdata.charat (0);                      if (((c>= ' a ' &&c<= ' Z ')    | |     (c>= ' A ' &&c<= ' Z '))                     {                             return   true;                    }else{                            return & nbsp; false;                      }             } &NBSP;&NBSP;3&NBSP: Judging Whether it is a Chinese character public boolean vd (STRING&NBSP;STR) {        char[] chars=str.tochararray ();     boolean isgb2312=false;      for (int i=0;i<chars.length;i++) {                 byte[] bytes= ("" +chars[i]). GetBytes ();                  if (bytes.length==2) {                               int[] ints=new int[2];                               ints[0]=bytes[0]& 0xff;                               ints[1]=bytes[1]& 0xff;                                 if (Ints[0]>=0x81 && ints[0]<=0xfe &&  ints[1] &GT;=0X40&NBSP;&AMP;&AMP;&NBSP;INTS[1]&LT;=0XFE) {                                           isGB2312=true;                                           break;                               }                  }     }      return isgb2312; }

Java judging numbers or Chinese or letters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.