With java code to distinguish a string inside what is Chinese, which is English?

  Abstract: java code to distinguish a string inside what is Chinese, which is English? 


  Because the website of the characters in length shown above are not the same, so pages is not a good appearance.    I wrote a marker for, in the realization of this issue do not know how to achieve. 



  Then characters will be judged by the decomposition of the corresponding ANSI code is greater than 127 



  Vacuumboy (study well and every day upward), the characters in the brackets is how to add? 



  Distinguish between use of the English in the regular expression 
  String str = "daf literati, Jiashou sdfs sd fsf"; 
  Str = str.replaceAll ( "[/ u4e00-/u9fa5 ]*",""); 
  All the Chinese have replaced swap 



  ANSI code appears to be the color?    ?    ? 
  Should be judged is ASCII………… 



  However, I would like to the landlord wanted was intercepted by the byte string bar 
  / ** 
  * The length byte string interception 
  * @ Param str will be intercepted string parameter 
  * @ Param toCount interception byte length 
  * @ Return after the interception return string 
  * / 
  Public String substring (String str, int toCount) ( 
  Int reInt = 0; 
  String reStr = ""; 
  If (str == null) 
  Return ""; 
  Char [] = tempChar str.toCharArray (); 
  For (int kk = 0; (kk <tempChar.length & toCount> reInt); kk + +) ( 
  String s1 = str.valueOf (tempChar [kk]); 
  Byte [] b = s1.getBytes (); 
  ReInt + = b.length; 
  TempChar reStr + = [kk]; 
  ) 

  Return reStr; 
  ) 



  Lip009 (dark blue melancholy) 
  I meant to ask, thank you! 
  However, there are also things that question a little bit. 
  For example, when the call to write 
  Substring ( "Y Ha ha Ha Ha", 4); 
  This time, the return of the "Y huh," so, more than a length byte. However, This is a good method. 



  This can be controlled, I wrote that filled the second half, the Chinese characters can not be half interception bar .. Oh course you can omit the last half swap 



  Jie posted a LZ 


  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , , ,

Releated Java Articles

Comments

Leave a Reply