Java logic code to determine the number of words

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.