<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
<channel>
<title>CSDN技术网摘 -- wz.csdn.net(字数统计)</title>
<description>CSDN技术网摘 -- wz.csdn.net(字数统计)</description>
<link>http://wz.csdn.net/tag-rss/字数统计/</link>
<generator>CSDN网摘 (http://wz.csdn.net)</generator>
<language>zh-cn</language>
<docs>CSDN网摘 包罗技术精华</docs>
<item>
<title>字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>字数统计</category>
<pubDate>Fri, 09 May 2008 08:05:50 GMT</pubDate>
<description><blockquote>比word先进的字数统计</blockquote></description>
<dc:creator>Freaky</dc:creator>
</item>
<item>
<title>好东西，大家以后说不定能用上，共享一下(顺便测试一下)！word 字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>word,字数统计</category>
<pubDate>Thu, 08 May 2008 13:51:10 GMT</pubDate>
<description><blockquote>word 字数统计</blockquote></description>
<dc:creator>UCJJff</dc:creator>
</item>
<item>
<title>比word先进的字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>java,字数统计</category>
<pubDate>Wed, 07 May 2008 07:21:32 GMT</pubDate>
<description><blockquote>比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 &amp;&amp; compriseSpace){
                //清除转义符
                String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //不包含符号包含空格
            else if(!compriseInterpunction &amp;&amp; compriseSpace){
                //使用正则表达式去掉指定的符号和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //包含指定符号不包含空格
            else if(compriseInterpunction &amp;&amp; !compriseSpace){
                //使用正则表达式去掉空格和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(SPACE)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //空格和指定符号都不包含
            else{
                //使用正则表达式去掉空格,指定符号和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex3 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(SPACE)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex3,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
        }
    }
    
    /**
     * 返回文章中的字数
     * @param wordCount 文章内容
     * @return
     */
    @SuppressWarnings(&quot;unused&quot;)
    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 = &quot;&quot;; 
            String s3 = &quot;&quot;; 
            String s1 = &quot;&quot;; 
            boolean bb = false; 
            if(wordContent.length()&gt;0){
                s4 = String.valueOf(wordContent.charAt(wordContent.length()-1)); 
            }
            for(int i=0; i&lt;wordContent.length(); 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)&amp;&amp;(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 &amp;&amp; compriseSpace){
            //清除转义符
            String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex,&quot; &quot;); 
            //首部的空格不算
            wordContent = wordContent.replaceAll(&quot;^\\s+&quot;,&quot;&quot;); 
            return wordContent.length(); 
        }//不包含符号包含空格
        else if(!compriseInterpunction &amp;&amp; compriseSpace){
            //首部的空格不算
            wordContent = wordContent.replaceAll(&quot;^\\s+&quot;,&quot;&quot;); 
            //使用正则表达式去掉指定的符号和转义符
            String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            String regex2 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
            wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
            return wordContent.length(); 
        }//包含指定符号不包含空格
        else if(compriseInterpunction &amp;&amp; !compriseSpace){
            //使用正则表达式去掉空格和转义符
            return this.getNoSpaceCount(wordContent); 
        }//空格和指定符号都不包含
        else{
            //使用正则表达式去掉指定符号
            String regex1 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
            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(&quot;^\\s+&quot;,&quot;&quot;); 
            wordContent = wordContent.replaceAll(&quot; &quot;,&quot;&quot;); 
            //使用正则替换转义符
            String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex,&quot;&quot;); 
            spaceCount = wordContent.length(); 
        }
        return spaceCount; 
    }
}</blockquote></description>
<dc:creator>yangyiqun01</dc:creator>
</item>
<item>
<title>比word先进的字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>java,字数统计</category>
<pubDate>Tue, 06 May 2008 15:00:02 GMT</pubDate>
<description><blockquote>比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 &amp;&amp; compriseSpace){
                //清除转义符
                String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //不包含符号包含空格
            else if(!compriseInterpunction &amp;&amp; compriseSpace){
                //使用正则表达式去掉指定的符号和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //包含指定符号不包含空格
            else if(compriseInterpunction &amp;&amp; !compriseSpace){
                //使用正则表达式去掉空格和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(SPACE)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
            //空格和指定符号都不包含
            else{
                //使用正则表达式去掉空格,指定符号和转义符
                String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
                String regex3 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
                String regex2 = &quot;[&quot;+new String(SPACE)+&quot;]&quot;; 
                wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
                wordContent = wordContent.replaceAll(regex3,&quot; &quot;); 
                return this.getWordCount(wordContent); 
            }
        }
    }
    
    /**
     * 返回文章中的字数
     * @param wordCount 文章内容
     * @return
     */
    @SuppressWarnings(&quot;unused&quot;)
    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 = &quot;&quot;; 
            String s3 = &quot;&quot;; 
            String s1 = &quot;&quot;; 
            boolean bb = false; 
            if(wordContent.length()&gt;0){
                s4 = String.valueOf(wordContent.charAt(wordContent.length()-1)); 
            }
            for(int i=0; i&lt;wordContent.length(); 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)&amp;&amp;(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 &amp;&amp; compriseSpace){
            //清除转义符
            String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex,&quot; &quot;); 
            //首部的空格不算
            wordContent = wordContent.replaceAll(&quot;^\\s+&quot;,&quot;&quot;); 
            return wordContent.length(); 
        }//不包含符号包含空格
        else if(!compriseInterpunction &amp;&amp; compriseSpace){
            //首部的空格不算
            wordContent = wordContent.replaceAll(&quot;^\\s+&quot;,&quot;&quot;); 
            //使用正则表达式去掉指定的符号和转义符
            String regex1 = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            String regex2 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
            wordContent = wordContent.replaceAll(regex2,&quot; &quot;); 
            return wordContent.length(); 
        }//包含指定符号不包含空格
        else if(compriseInterpunction &amp;&amp; !compriseSpace){
            //使用正则表达式去掉空格和转义符
            return this.getNoSpaceCount(wordContent); 
        }//空格和指定符号都不包含
        else{
            //使用正则表达式去掉指定符号
            String regex1 = &quot;[&quot;+new String(CHS)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex1,&quot; &quot;); 
            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(&quot;^\\s+&quot;,&quot;&quot;); 
            wordContent = wordContent.replaceAll(&quot; &quot;,&quot;&quot;); 
            //使用正则替换转义符
            String regex = &quot;[&quot;+new String(CHN)+&quot;]&quot;; 
            wordContent = wordContent.replaceAll(regex,&quot;&quot;); 
            spaceCount = wordContent.length(); 
        }
        return spaceCount; 
    }
}</blockquote></description>
<dc:creator>guorabbit</dc:creator>
</item>
<item>
<title>好东西，大家以后说不定能用上，共享一下(顺便测试一下)！字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>字数统计</category>
<pubDate>Mon, 05 May 2008 13:06:20 GMT</pubDate>
<description><blockquote>据说比word还牛的字数统计程序</blockquote></description>
<dc:creator>zzh375502759</dc:creator>
</item>
<item>
<title>比word先进的字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>java,字数统计</category>
<pubDate>Mon, 05 May 2008 04:38:25 GMT</pubDate>
<description><blockquote>字数统计</blockquote></description>
<dc:creator>zhengpeiyong</dc:creator>
</item>
<item>
<title>好东西，大家以后说不定能用上，共享一下(顺便测试一下)！</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>字数统计</category>
<pubDate>Wed, 30 Apr 2008 16:47:12 GMT</pubDate>
<description><blockquote>比word先进的字数统计</blockquote></description>
<dc:creator>chenshuangjiang</dc:creator>
</item>
<item>
<title>字数统计</title>
<link>http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</link>
<guid isPermaLink="true">http://topic.csdn.net/u/20080424/04/279b07e4-a5a2-4af6-a285-6081db222d62.html</guid>
<category>字数统计</category>
<pubDate>Fri, 25 Apr 2008 05:58:36 GMT</pubDate>
<description><blockquote>字数统计</blockquote></description>
<dc:creator>zhusiqin</dc:creator>
</item>
</channel></rss>
