Java determines whether a Chinese character is garbled to determine whether a string is a double integer number

Source: Internet
Author: User

/**
  * Determine if it is a Chinese character
  * 
  * @param str
  * @return
  */
 public Static Boolean ISGBK (String str) {
  char[] chars = Str.tochararray ();
  boolean ISGBK = 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] >= 0x40
 & nbsp;    && ints[1] <= 0xFE) {
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ISGBK = true;
     break;
    }
   }
  }
  return ISGBK;
 }

/**
  * To determine if it is garbled
  * 
  * @param str
  * @return
  */
 public Static Boolean Ismessycode (String str) {
  for (int i = 0; i < str.length (); i++) {
   c Har C = Str.charat (i);
   //when converting from Unicode encoding to a character set, if there is no corresponding encoding in that character set, you get 0x3f (that is, the question mark character?)
   // When converting from another character set to a Unicode encoding, if the binary number does not identify any characters in the character set, the result is 0xfffd
   //system.out.println ("---" + (int ) c);
   if (int) c = = 0xfffd) {
    //there is a garbled
    // System.out.println ("There is garbled" + (int) c);
    return true;
   }
  }
  return false; 
 }


/**
* Determines whether a string is a double integer number
*
* @param str
* @return
*/
public static Boolean isdouble (String str) {
if (Stringutil.isnullorempty (str)) {
return false;
}
Pattern p = pattern.compile ("-*\\d*.\\d*");
Pattern p = pattern.compile ("-*" + "\\d*" + ".") + "\\d*");
return P.matcher (str). matches ();
}

/**
* Determines whether the string is an integer word
*
* @param str
* @return
*/
public static Boolean isnumber (String str) {
if (Stringutil.isnullorempty (str)) {
return false;
}
Pattern p = pattern.compile ("-*\\d*");
return P.matcher (str). matches ();
}

/**
* Judging whether it is a number
*
* @param str
* @return
*/
public static Boolean isnumeric (String str)
{
Pattern pattern = Pattern.compile ("[0-9]*");
Matcher isnum = Pattern.matcher (str);
if (!isnum.matches ()) {
return false;
}
return true;
}

Need to import Java.util.regex.Pattern and Java.util.regex.Matcher

From:http://hi.baidu.com/zdz8207/item/13abe809f904c718eafe38d5

Java determines whether a Chinese character is garbled to determine whether a string is a double integer number

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.