检出字符串中的中文 java版

星期日, 2010-12-05 | Author: Lee | JAVA-and-J2EE | 3,710 views

话不多说了,就是检出字符串中的中文而已,直接上代码了,没有什么难的了!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.liyz.test.str;
public class TestChinese {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String str="中文国际 id chinese ? test  power by I5A6!!";
		String s=getChineseStr(str);
		System.out.println(s);
		System.out.println(s.length());
	}
 
	/**
	 * 检出其中的中文部分
	 * @param str
	 * @return
	 */
	public static String getChineseStr(String str){
		StringBuffer sb=new StringBuffer();
		String tempStr;
		for(int i=0;i<str.length();i++){
			tempStr=String.valueOf(str.charAt(i));
			if(tempStr.getBytes().length==2){
				sb.append(tempStr);
			}
		}
		return sb.toString();
	}
}

Tags: , ,

文章作者: Lee

本文地址: https://www.pomelolee.com/709.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

文章分类

Links

Meta