首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 数据库 第二书店 程序员

好东西,大家以后说不定能用上,共享一下(顺便测试一下)!


比word先进的字数统计
我测试过了,基本接近完美,但是肯定还有BUG 望提出!谢谢

Java code
package taotao.montao.demo;

/**
* 获取文章的字数或则字符数
* @author montao
*/
public class StatWordCount {

private final char[] CHS = {',',';','.','!','?',';','+','。','?','!'}; //符号数组

private final char[] CHN = {'\n','\r'}; //转义符数组

private final char[] SPACE = {' ',' '}; //空格的数组(前半角,后全角)

/**
* 根据指定条件来筛选文章的字数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定字符
* @param compriseSpace 是否包含空格
* @return 返回文章经过指定筛选后的长度
*/
public int getWordCount(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
if(wordContent==null){
return 0;
}else if(wordContent.length()==0){
return 0;
}else{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
return this.getWordCount(wordContent);
}
//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//空格和指定符号都不包含
else{
//使用正则表达式去掉空格,指定符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex3 = "["+new String(CHS)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
wordContent = wordContent.replaceAll(regex3," ");
return this.getWordCount(wordContent);
}
}
}

/**
* 返回文章中的字数
* @param wordCount 文章内容
* @return
*/
@SuppressWarnings("unused")
private int getWordCount(String wordContent){
int count = 0;
if(wordContent==null){ //判断是否为null,如果为null直接返回0
count = 0;
}else if(wordContent.length()==0){ //判断是否为空,如果为空直接返回0
count = 0;
}else{ //判断获取字数
wordContent = wordContent.trim(); //清空空格
//临时变量
String s4 = "";
String s3 = "";
String s1 = "";
boolean bb = false;
if(wordContent.length()>0){
s4 = String.valueOf(wordContent.charAt(wordContent.length()-1));
}
for(int i=0;i s3 = String.valueOf(wordContent.charAt(i));
int num = s3.getBytes().length;
if(s3.hashCode()==32||s3.getBytes().length==2){
bb=true;
}if(num==2){
count++;
}else{
if(i+11)){
s1 = String.valueOf(wordContent.charAt(i+1));
if((s1.hashCode()==32||s1.getBytes().length==2)&&(s3.hashCode()!=32)){
count++;
}
}
}
}
if(!bb){
count++;
}else{
if(s4.getBytes().length==1){
count++;
}
}
}
return count;
}

/**
* 根据条件来获取文章的字符数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定符号
* @param compriseSpace 是否包含空格
* @return 返回字符长度
*/
public int getWordCharacter(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
return wordContent.length();
}//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return wordContent.length();
}//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
return this.getNoSpaceCount(wordContent);
}//空格和指定符号都不包含
else{
//使用正则表达式去掉指定符号
String regex1 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
return this.getNoSpaceCount(wordContent);
}
}

/**
* 获取文章中非空格的字符总数
* @param wordContent 文章内容
* @return
*/
private int getNoSpaceCount(String wordContent) {
int spaceCount = 0;
if(wordContent==null)
{
spaceCount = 0;
}else if(wordContent.length()==0)
{
spaceCount = 0;
}else
{
//替换首部的
wordContent = wordContent.replaceAll("^\\s+","");
wordContent = wordContent.replaceAll(" ","");
//使用正则替换转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex,"");
spaceCount = wordContent.length();
}
return spaceCount;
}
}




他们设置了哪些标签:


code) java Word word先进的字数统计 word源代码 比word先进的字数统计 不知道有什么作用 程序代码(java 获取文章字数或字符数 计算文章字数的方法 技术 数据结构 数字统计 算法 统计 统计字数 文档计数器 文字统计 学习 一些代码 以后有可能用上 用java实现的word字数统计 字数统计 字数统计方法

谁收藏了这个网址:


shheagle收录

时间:2008-4-24 10:32:05 | 相关网摘

babyjojoyoyo收录

时间:2008-4-24 10:34:50 | 相关网摘

cnjzy0106收录

使用标签:数字统计,时间:2008-4-24 10:58:00 | 相关网摘

wangbinwork收录

时间:2008-4-24 12:17:34 | 相关网摘

比word先进的字数统计

k7sem收录

时间:2008-4-24 13:28:24 | 相关网摘

比word先进的字数统计

fusmile收录

时间:2008-4-24 14:55:26 | 相关网摘

i_mimi收录

时间:2008-4-24 16:54:25 | 相关网摘

lt1234收录

时间:2008-4-24 19:49:26 | 相关网摘

java2times收录

时间:2008-4-24 20:33:34 | 相关网摘

lflljt收录

时间:2008-4-24 21:26:52 | 相关网摘

zuoan911收录

时间:2008-4-24 22:10:08 | 相关网摘

读懂,但是先收藏了再说,没准什么时候就用到

Mike_Luo收录

时间:2008-4-24 22:21:14 | 相关网摘

学里面的算法课认真上过一半,或者毕业后认真写过2年程序,算法就不会写成这样了.

Joseplin收录

时间:2008-4-24 22:36:13 | 相关网摘

focuswe收录

时间:2008-4-24 22:43:39 | 相关网摘

pifengtao收录

时间:2008-4-24 22:54:51 | 相关网摘

guoqiangone收录

使用标签:不知道有什么作用,时间:2008-4-25 8:20:25 | 相关网摘

jeffrey0409收录

时间:2008-4-25 9:04:04 | 相关网摘

FL1429收录

时间:2008-4-25 9:52:00 | 相关网摘

wangju309收录

时间:2008-4-25 11:13:38 | 相关网摘

字数统计

pear0808收录

时间:2008-4-25 12:56:41 | 相关网摘

HKCID收录

时间:2008-4-25 13:46:44 | 相关网摘

比word先进的字数统计

zhusiqin收录

使用标签:字数统计,时间:2008-4-25 13:58:36 | 相关网摘

字数统计

li_d_s收录

时间:2008-4-25 14:02:23 | 相关网摘

kcgee收录

时间:2008-4-25 17:25:11 | 相关网摘

liangxiao_728收录

使用标签:java,时间:2008-4-25 21:57:50 | 相关网摘

rabbit_zizhu收录

使用标签:比word先进的字数统计,时间:2008-4-25 22:31:09 | 相关网摘

比word先进的字数统计

liuyue01收录

使用标签:文档计数器,时间:2008-4-25 22:41:49 | 相关网摘

huoyanxueren收录

时间:2008-4-25 23:55:23 | 相关网摘

bluecll收录

使用标签:java,时间:2008-4-26 0:19:46 | 相关网摘

wuchunzhi收录

时间:2008-4-26 2:05:47 | 相关网摘

wizweb收录

时间:2008-4-26 10:54:31 | 相关网摘

比word先进的字数统计

wenmingfeng收录

时间:2008-4-26 11:26:33 | 相关网摘

tomboy1986收录

使用标签:以后有可能用上,时间:2008-4-27 1:46:34 | 相关网摘

kukou收录

时间:2008-4-27 15:12:49 | 相关网摘

xiaoxiao8372收录

时间:2008-4-27 19:13:48 | 相关网摘

zxlam收录

时间:2008-4-28 12:41:43 | 相关网摘

比word千里的被除数统计.

lanlan520收录

时间:2008-4-28 13:54:50 | 相关网摘

yan55667收录

时间:2008-4-28 15:14:48 | 相关网摘

sixme收录

时间:2008-4-28 17:55:19 | 相关网摘

zhili234收录

时间:2008-4-29 13:24:05 | 相关网摘

xmxoxo收录

时间:2008-4-29 15:39:25 | 相关网摘

sxoo0305收录

使用标签:数据结构,时间:2008-4-29 18:15:06 | 相关网摘

源代码

youyou1225收录

使用标签:获取文章字数或字符数,时间:2008-4-29 22:05:28 | 相关网摘

pwcs_收录

时间:2008-4-30 10:12:00 | 相关网摘

zhouhong0801收录

时间:2008-4-30 10:20:07 | 相关网摘

接近完美,但是肯定还

Ablan_Wang收录

时间:2008-4-30 17:38:56 | 相关网摘

chenshuangjiang收录

使用标签:字数统计,时间:2008-5-1 0:47:12 | 相关网摘

比word先进的字数统计

mdog26收录

时间:2008-5-1 22:27:22 | 相关网摘

字数统计

yqsshr收录

时间:2008-5-1 23:16:25 | 相关网摘

kobe6111收录

时间:2008-5-2 13:09:34 | 相关网摘

java做的字数统计

guxing678收录

时间:2008-5-2 15:38:07 | 相关网摘

zhouwangzong收录

使用标签:技术,时间:2008-5-3 0:30:31 | 相关网摘

wllpw收录

时间:2008-5-3 9:00:03 | 相关网摘

henglin收录

时间:2008-5-3 21:44:53 | 相关网摘

wensheng_zh2007收录

时间:2008-5-4 0:15:57 | 相关网摘

ssh000收录

时间:2008-5-4 8:15:51 | 相关网摘

wildwise收录

时间:2008-5-4 9:35:00 | 相关网摘

HL20913538收录

时间:2008-5-4 10:17:16 | 相关网摘

echojiji收录

时间:2008-5-4 11:04:07 | 相关网摘

xiw_neusoft收录

使用标签:统计字数,时间:2008-5-4 12:37:25 | 相关网摘

统计字数

mickdong收录

时间:2008-5-4 13:18:02 | 相关网摘

比word先进的字数统计
我测试过了,基本接近完美,但是肯定还有BUG 望提出!谢谢

token1984收录

时间:2008-5-4 14:17:26 | 相关网摘

zhao_tk收录

时间:2008-5-4 14:48:11 | 相关网摘

pgameli收录

使用标签:计算文章字数的方法,时间:2008-5-4 19:00:11 | 相关网摘

Rainland_Lee收录

时间:2008-5-4 19:01:15 | 相关网摘

talentxie收录

时间:2008-5-4 20:42:18 | 相关网摘

sknice收录

使用标签:比word先进的字数统计,时间:2008-5-5 8:52:25 | 相关网摘

比word先进的字数统计

ldxfsh收录

时间:2008-5-5 11:37:05 | 相关网摘

String

weikai4321收录

时间:2008-5-5 12:16:37 | 相关网摘

zhengpeiyong收录

使用标签:java, 字数统计,时间:2008-5-5 12:38:25 | 相关网摘

字数统计

macaw收录

时间:2008-5-5 12:38:59 | 相关网摘

montao写的

bigfoot001收录

时间:2008-5-5 15:16:12 | 相关网摘

andy861025收录

时间:2008-5-5 15:16:36 | 相关网摘

户刊登文字广告是按照字数来计费的,但是有时候又不会包含特定符号和空格,所以列出了8种情况!我测试过处理8W多字的文章2

logi22收录

时间:2008-5-5 15:25:49 | 相关网摘

字数统计

MattHgh收录

使用标签:java,时间:2008-5-5 17:21:16 | 相关网摘

比word先进的字数统计

youyouzizi收录

使用标签:word源代码,时间:2008-5-5 18:22:51 | 相关网摘

DoomGT收录

时间:2008-5-5 18:53:36 | 相关网摘

研究研究

vip_zhujing收录

使用标签:字数统计方法,时间:2008-5-5 20:54:58 | 相关网摘

zzh375502759收录

使用标签:字数统计,时间:2008-5-5 21:06:20 | 相关网摘

据说比word还牛的字数统计程序

suzuqing收录

时间:2008-5-5 22:44:00 | 相关网摘

hzzz_lgh3399收录

时间:2008-5-6 9:07:35 | 相关网摘

zkb9604收录

时间:2008-5-6 11:23:27 | 相关网摘

guoyaxin895收录

使用标签:算法,时间:2008-5-6 14:04:02 | 相关网摘

gl0312收录

时间:2008-5-6 15:39:46 | 相关网摘

svpan收录

使用标签:一些代码,时间:2008-5-6 20:36:24 | 相关网摘

yungts收录

时间:2008-5-6 21:01:06 | 相关网摘

guorabbit收录

使用标签:java, 字数统计,时间:2008-5-6 23:00:02 | 相关网摘

比word先进的字数统计
我测试过了,基本接近完美,但是肯定还有BUG 望提出!谢谢

Java code
package taotao.montao.demo;

/**
* 获取文章的字数或则字符数
* @author montao
*/
public class StatWordCount {

private final char[] CHS = {',',';','.','!','?',';','+','。','?','!'}; //符号数组

private final char[] CHN = {'\n','\r'}; //转义符数组

private final char[] SPACE = {' ',' '}; //空格的数组(前半角,后全角)

/**
* 根据指定条件来筛选文章的字数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定字符
* @param compriseSpace 是否包含空格
* @return 返回文章经过指定筛选后的长度
*/
public int getWordCount(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
if(wordContent==null){
return 0;
}else if(wordContent.length()==0){
return 0;
}else{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
return this.getWordCount(wordContent);
}
//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//空格和指定符号都不包含
else{
//使用正则表达式去掉空格,指定符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex3 = "["+new String(CHS)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
wordContent = wordContent.replaceAll(regex3," ");
return this.getWordCount(wordContent);
}
}
}

/**
* 返回文章中的字数
* @param wordCount 文章内容
* @return
*/
@SuppressWarnings("unused")
private int getWordCount(String wordContent){
int count = 0;
if(wordContent==null){ //判断是否为null,如果为null直接返回0
count = 0;
}else if(wordContent.length()==0){ //判断是否为空,如果为空直接返回0
count = 0;
}else{ //判断获取字数
wordContent = wordContent.trim(); //清空空格
//临时变量
String s4 = "";
String s3 = "";
String s1 = "";
boolean bb = false;
if(wordContent.length()>0){
s4 = String.valueOf(wordContent.charAt(wordContent.length()-1));
}
for(int i=0;i s3 = String.valueOf(wordContent.charAt(i));
int num = s3.getBytes().length;
if(s3.hashCode()==32||s3.getBytes().length==2){
bb=true;
}if(num==2){
count++;
}else{
if(i+11)){
s1 = String.valueOf(wordContent.charAt(i+1));
if((s1.hashCode()==32||s1.getBytes().length==2)&&(s3.hashCode()!=32)){
count++;
}
}
}
}
if(!bb){
count++;
}else{
if(s4.getBytes().length==1){
count++;
}
}
}
return count;
}

/**
* 根据条件来获取文章的字符数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定符号
* @param compriseSpace 是否包含空格
* @return 返回字符长度
*/
public int getWordCharacter(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
return wordContent.length();
}//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return wordContent.length();
}//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
return this.getNoSpaceCount(wordContent);
}//空格和指定符号都不包含
else{
//使用正则表达式去掉指定符号
String regex1 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
return this.getNoSpaceCount(wordContent);
}
}

/**
* 获取文章中非空格的字符总数
* @param wordContent 文章内容
* @return
*/
private int getNoSpaceCount(String wordContent) {
int spaceCount = 0;
if(wordContent==null)
{
spaceCount = 0;
}else if(wordContent.length()==0)
{
spaceCount = 0;
}else
{
//替换首部的
wordContent = wordContent.replaceAll("^\\s+","");
wordContent = wordContent.replaceAll(" ","");
//使用正则替换转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex,"");
spaceCount = wordContent.length();
}
return spaceCount;
}
}

JavaLover00000收录

使用标签:Java,时间:2008-5-7 11:00:35 | 相关网摘

java小程序

superwkl收录

时间:2008-5-7 11:01:02 | 相关网摘

lijie250收录

时间:2008-5-7 11:04:46 | 相关网摘

pangtaitao收录

时间:2008-5-7 11:29:09 | 相关网摘

iwaterstone收录

时间:2008-5-7 13:00:59 | 相关网摘

zhuche110收录

时间:2008-5-7 13:28:43 | 相关网摘

xiaojianpitt收录

时间:2008-5-7 13:44:18 | 相关网摘

比word先进的字数统计

xihaxiha9712收录

时间:2008-5-7 15:10:16 | 相关网摘

yangyiqun01收录

使用标签:java, 字数统计,时间:2008-5-7 15:21:32 | 相关网摘

比word先进的字数统计
我测试过了,基本接近完美,但是肯定还有BUG 望提出!谢谢

Java code
package taotao.montao.demo;

/**
* 获取文章的字数或则字符数
* @author montao
*/
public class StatWordCount {

private final char[] CHS = {',',';','.','!','?',';','+','。','?','!'}; //符号数组

private final char[] CHN = {'\n','\r'}; //转义符数组

private final char[] SPACE = {' ',' '}; //空格的数组(前半角,后全角)

/**
* 根据指定条件来筛选文章的字数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定字符
* @param compriseSpace 是否包含空格
* @return 返回文章经过指定筛选后的长度
*/
public int getWordCount(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
if(wordContent==null){
return 0;
}else if(wordContent.length()==0){
return 0;
}else{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
return this.getWordCount(wordContent);
}
//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return this.getWordCount(wordContent);
}
//空格和指定符号都不包含
else{
//使用正则表达式去掉空格,指定符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex3 = "["+new String(CHS)+"]";
String regex2 = "["+new String(SPACE)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
wordContent = wordContent.replaceAll(regex3," ");
return this.getWordCount(wordContent);
}
}
}

/**
* 返回文章中的字数
* @param wordCount 文章内容
* @return
*/
@SuppressWarnings("unused")
private int getWordCount(String wordContent){
int count = 0;
if(wordContent==null){ //判断是否为null,如果为null直接返回0
count = 0;
}else if(wordContent.length()==0){ //判断是否为空,如果为空直接返回0
count = 0;
}else{ //判断获取字数
wordContent = wordContent.trim(); //清空空格
//临时变量
String s4 = "";
String s3 = "";
String s1 = "";
boolean bb = false;
if(wordContent.length()>0){
s4 = String.valueOf(wordContent.charAt(wordContent.length()-1));
}
for(int i=0;i s3 = String.valueOf(wordContent.charAt(i));
int num = s3.getBytes().length;
if(s3.hashCode()==32||s3.getBytes().length==2){
bb=true;
}if(num==2){
count++;
}else{
if(i+11)){
s1 = String.valueOf(wordContent.charAt(i+1));
if((s1.hashCode()==32||s1.getBytes().length==2)&&(s3.hashCode()!=32)){
count++;
}
}
}
}
if(!bb){
count++;
}else{
if(s4.getBytes().length==1){
count++;
}
}
}
return count;
}

/**
* 根据条件来获取文章的字符数
* @param wordContent 文章内容
* @param compriseInterpunction 是否包含指定符号
* @param compriseSpace 是否包含空格
* @return 返回字符长度
*/
public int getWordCharacter(String wordContent,boolean compriseInterpunction,boolean compriseSpace)
{
//既要包含符号又要包含空格
if(compriseInterpunction && compriseSpace){
//清除转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex," ");
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
return wordContent.length();
}//不包含符号包含空格
else if(!compriseInterpunction && compriseSpace){
//首部的空格不算
wordContent = wordContent.replaceAll("^\\s+","");
//使用正则表达式去掉指定的符号和转义符
String regex1 = "["+new String(CHN)+"]";
String regex2 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
wordContent = wordContent.replaceAll(regex2," ");
return wordContent.length();
}//包含指定符号不包含空格
else if(compriseInterpunction && !compriseSpace){
//使用正则表达式去掉空格和转义符
return this.getNoSpaceCount(wordContent);
}//空格和指定符号都不包含
else{
//使用正则表达式去掉指定符号
String regex1 = "["+new String(CHS)+"]";
wordContent = wordContent.replaceAll(regex1," ");
return this.getNoSpaceCount(wordContent);
}
}

/**
* 获取文章中非空格的字符总数
* @param wordContent 文章内容
* @return
*/
private int getNoSpaceCount(String wordContent) {
int spaceCount = 0;
if(wordContent==null)
{
spaceCount = 0;
}else if(wordContent.length()==0)
{
spaceCount = 0;
}else
{
//替换首部的
wordContent = wordContent.replaceAll("^\\s+","");
wordContent = wordContent.replaceAll(" ","");
//使用正则替换转义符
String regex = "["+new String(CHN)+"]";
wordContent = wordContent.replaceAll(regex,"");
spaceCount = wordContent.length();
}
return spaceCount;
}
}

shiling40a收录

时间:2008-5-7 20:15:35 | 相关网摘

juneapple收录

时间:2008-5-8 10:30:43 | 相关网摘

lisl2003收录

时间:2008-5-8 10:41:06 | 相关网摘

字数统计,关注47楼和62楼

WIN_ANGEL收录

时间:2008-5-8 11:15:02 | 相关网摘


网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
北京百联美达美数码科技有限公司 版权所有 京 ICP 证 020026 号
Copyright © 2000-2006, CSDN.NET, All Rights Reserved