Java full-width conversion

Source: Internet
Author: User

Full-width to half-width rules: 1. The full-width space is 12288, and the half-width space is 32 special processing; 2. Other characters (33-126) and the full-width (65281-65374) is 65248 different. Java full-width conversion code:

/*** StringUtils *** @ author tongqian. zhang */public class StringUtils {/*** determines whether the String is null or an empty String * @ param str the original String * @ return */public static boolean isEmpty (String str) {return str = null | "". equals (str);}/*** fullwidth to halfwidth: * @ param fullStr * @ return */public static final String full2Half (String fullStr) {if (isEmpty (fullStr )) {return fullStr;} char [] c = fullStr. toCharArray (); for (int I = 0; I <c. length; I ++) {if (c [I]> = 65281 & c [I] <= 65374) {c [I] = (char) (c [I]-65248);} else if (c [I] = 12288) {// Space c [I] = (char) 32 ;}} return new String (c);}/*** halfwidth to fullwidth * @ param halfStr * @ return */public static final String half2Full (String halfStr) {if (isEmpty (halfStr) {return halfStr;} char [] c = halfStr. toCharArray (); for (int I = 0; I <c. length; I ++) {if (c [I] = 32) {c [I] = (char) 12288;} else if (c [I] <127) {c [I] = (char) (c [I] + 65248) ;}return new String (c );}}

 


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.