java逻辑代码_Java逻辑代码判断字数
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;
}
}
原文:http://www.cnblogs.com/weyine/p/7613579.html
總結
以上是生活随笔為你收集整理的java逻辑代码_Java逻辑代码判断字数的全部內容,希望文章能夠幫你解決所遇到的問題。