标签:符号 equal als .com chinese turn sub nbsp 标点符号
package cn.com.f_young.erp.util;
public class WorldTrueCount {
/**
* 判断中文和标点符号的逻辑代码
* @param value
* @return
*/
public static int String_length_chinese(String value) {
int valueLength = 0;
String chinese = "[\u4e00-\u9fa5]";
String english = "[a-zA-Z]";
for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1);
if(temp.equals(" ")){
valueLength+=0;
}else if (temp.matches(chinese)) {
valueLength += 1;
}else if(temp.matches(english)) {
valueLength += 0;
}else{
valueLength += 1;
}
}
return valueLength;
}
/**
* 判断英文的逻辑代码
* @param value
* @return
*/
public static int String_length_english(String value) {
int valueLength = 1;
String chinese = "[\u4e00-\u9fa5]";
String english = "[a-zA-Z]";
int k=0;
for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1);
if(temp.equals(" ")){
if(k==1){
valueLength+=1;
k=0;
}
valueLength+=0;
}else if (temp.matches(chinese)) {
if(k==1){
valueLength+=1;
k=0;
}
valueLength += 0;
}else if(temp.matches(english)) {
k = 1;
valueLength += 0;
}else{
if(k==1){
valueLength+=1;
k=0;
}
valueLength += 0;//标点符号
}
}
return valueLength;
}
}
标签:符号 equal als .com chinese turn sub nbsp 标点符号
原文地址:http://www.cnblogs.com/weyine/p/7613579.html