java判斷 字符串 是否有漢字
判斷字符串是否包含漢字 并且替換成ASCLL
private static String regEx = "[\\u4e00-\\u9fa5]";
/**
* 判斷字符串是否包含漢字 并且替換成ASCLL
*
* @param str_para
* @return str_result
*/
private static String isChinese_Replace( String str_para )
{
Pattern p = Pattern.compile( regEx );
String str_result = str_para;
String str_0 = "";
String str_1 = "";
String str_data[] = null;
String str_return_reslut = "";
if ( str_result != null && str_result.trim().length() > 0 )
{
try {
str_data = str_result.split( "" );
for ( int i = 0; i < str_data.length; i++ )
{
Matcher m = p.matcher( str_data[i] );
/* L.d(str_data[i]); */
int count = 0;
if ( m.find() )
{
count++;
str_result = m.group( 0 );
byte[] b = str_result.getBytes( "GBK" );
str_0 = Integer.toHexString( b[0] );
str_1 = Integer.toHexString( b[1] );
str_return_reslut = str_return_reslut + "/" + conver10( str_0 ) + conver10( str_1 ) + "/";
} else {
str_return_reslut = str_return_reslut + str_data[i];
}
}
} catch ( NumberFormatException e ) {
e.printStackTrace();
} catch ( UnsupportedEncodingException e ) {
e.printStackTrace();
}
} else {
return(str_return_reslut);
}
return(str_return_reslut);
}
/* 字符串轉換十進制 */
public static int conver10( String str_0 )
{
return(Integer.parseInt( str_0.substring( str_0.length() - 2, str_0.length() ), 16 ) );
} 本文由用戶 cenmin 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!