Tool Method for converting full-width to half-width to simplified and large-write to lower-case

Source: Internet
Author: User
Public class charcodeutils {Private Static charsetconverter cc = new charsetconverter (10); Private Static logger = logger. getlogger (charcodeutils. class); Private Static Boolean hasinit = false;/*** get the configuration file path string [] ** @ return **/Private Static string getfileloc () throws domainexception {string filepath = ""; try {java.net. URL classurl = charcodeutils. class. getresource (""); filepath = classu RL. getpath ();} catch (exception e) {logger. Error ("An error occurred while obtaining the absolute path of the charmap file! ");} Logger.info (" filepath is: "+ filepath); If (filepath. indexof (". Jar ")! =-1) {string jarfile = filepath. tostring (). substring (5, filepath. tostring (). length ()-24); logger.info ("jarfile is:" + jarfile); try {jarfile1_jfo = new jarfile1_( jarfile); Return jfo. extrafiletopath ();} catch (exception e) {logger. error ("An error occurred while extracting the jar package! ", E); throw new domainexception (" can't get charmap file from jar: "+ jarfile) ;}} else {return filepath. tostring (). substring (0, filepath. tostring (). length ()-22) + "charmap" ;}}/*** initialize charcodeutils and load the corresponding encoding configuration file void **/Private Static void Init () throws domainexception {If (! Hasinit) {string Path = getfileloc () + file. separator; CC. setfiles (New String [] {path + "uct2s. CTB ", // convert traditional to simplified path +" ucs2t. CTB ", // simplified to traditional path +" ucsbc2dbc. CTB ", // convert the full-width to the half-width null, null, path +" ucint2ext. CTB ", path +" ucrglt. CTB ", path +" ucphrase. CTB ",}); CC. init (); hasinit = true; }}/ *** traditional to simplified void ** @ Param orstring **/public static string T2S (string orstring) throws domainexception {Init (); Return CC. map (0, orstring);}/*** simplified to traditional void ** @ Param orstring **/public static string s2t (string orstring) throws domainexception {Init (); return CC. map (1, orstring);}/*** fullwidth to halfwidth void ** @ Param orstring **/public static string w2h (string orstring) throws domainexception {Init (); return CC. map (2, orstring);}/*** string used by stringutils ** @ Param orstring * @ return * @ throws domainexception **/public static String qbchange (string orstring) throws domainexception {Init (); // logger.info ("qbchange:" + orstring); Return CC. map (2, CC. map (0, orstring);}/*** convert special symbol ** @ Param Str * @ return */public static string changess (string Str) {STR = stringutils. replace (STR, "'", "·"); STR = stringutils. replace (STR, "'", "'"); STR = stringutils. replace (STR, "\" "," "); STR = stringutils. replace (STR, "); STR = stri Ngutils. Replace (STR, ";", ";"); STR = stringutils. Replace (STR ,".",". "); STR = stringutils. Replace (STR,": ",": "); STR = stringutils. Replace (STR ,"? ","? "); STR = stringutils. Replace (STR ,"! ","! "); STR = stringutils. replace (STR, "\", "\"); STR = stringutils. replace (STR, "<", "<"); STR = stringutils. replace (STR, ">", ">"); Return STR ;} /*** main method void *** @ Param argz **/public static void main (string [] argz) throws domainexception {qbchange ("ABC ");}}

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.