[Java] Full half-width cross-turn of strings

Source: Internet
Author: User


<pre name= "code" class= "java" >/** * <DL> * <DT><B> function Description </B></DT> * Full half-width of strings * </dl     > * @author Hailan */public class Sbcchange {//public static void main (string[] args) {////string qjstr = "full-width turning half-angle DAO Zhe 4 ";//system.out.println (Qjstr.length () +" =length "),//qjstr.replaceall (" [] "," ");//system.out.println (QJstr.length () + "=replacelengthr");//string todbcres = Todbc (QJSTR);//system.out.println (Qjstr + "\ndb" + todbcres);////String  Qbres = Bqchange (qjstr)//system.out.println (qjstr + "\NBQ" + qbres)//}//half-width to full-width/** * <b> function Description </b> * Half-width Chinese character to full-width kanji  * @param qjstr Half-width * @return Full-width String * <p> * <b> Example:</b><br> * Use example Description * String a = Bqchange ("Approval") * </p> */public static Final String bqchange (string qjstr) {String outstr = ""; String tstr = ""; byte[] b = null;for (int i = 0; I < qjstr.length (); i++) {try {tstr = qjstr.substring (i, i + 1); b = Tstr.getbytes ("Unicode");} catch (Java.io.UnsupportedEncodingException e) {E.prinTstacktrace ();} if (b[3]! =-1) {b[2] = (byte) (b[2]-+); B[3] = -1;try {outstr = outstr + new String (b, "Unicode");} catch (Java.io.Unsu Pportedencodingexception e) {e.printstacktrace ();}} Elseoutstr = Outstr + tstr;} return outstr;} /** * <b> Function Description </b> * Full-width Turn half-width * @param input full-width String * @return * <p> * <b> Example:</b><br> * Use example Child Description * String a = Todbc ("Re") * </p> */public static String todbc (string input) {char[] c = Input.tochararray (); for ( int i = 0; i < c.length; i++) {if (c[i] = = 12288) {C[i] = (char) 32;continue;} if (C[i] > 65280 && c[i] < 65375) C[i] = (char) (C[i]-65248);} return new String (c);}}




[Java] Full half-width cross-turn of strings

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.