Package cn.com.f_young.erp.util;
public class Worldtruecount {
/**
* Logic code for judging Chinese and punctuation
* @param value
* @return
*/
public static int String_length_chinese (String value) {
int valuelength = 0;
String Chinese = "[\u4e00-\u9fa5]";
String 中文版 = "[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 (中文版)) {
Valuelength + = 0;
}else{
Valuelength + = 1;
}
}
return valuelength;
}
/**
* To judge the logic code of English
* @param value
* @return
*/
public static int String_length_english (String value) {
int valuelength = 1;
String Chinese = "[\u4e00-\u9fa5]";
String 中文版 = "[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 (中文版)) {
K = 1;
Valuelength + = 0;
}else{
if (k==1) {
Valuelength+=1;
k=0;
}
Valuelength + = 0;//punctuation
}
}
return valuelength;
}
}
Java logic code to determine the number of words