/**
* 獲取文章的字數或者字元數
* @author
montao
*/public
class
statwordcount ;
//符號陣列
private
final
char
chn =;
//轉義符陣列
private
final
char
space =;
//空格的陣列(前半形,後全形)
/*** 根據指定條件來篩選文章的字數
* @param
wordcontent 文章內容
* @param
compriseinterpunction 是否包含指定字元
* @param
comprisespace 是否包含空格
* @return
返回文章經過指定篩選後的長度
*/public
intgetwordcount(string wordcontent,
boolean
compriseinterpunction,
boolean
comprisespace)
else
if(wordcontent.length()==0
)else
//不包含符號包含空格
elseif(
!compriseinterpunction
&&comprisespace)
//包含指定符號不包含空格
else
if(compriseinterpunction &&!
comprisespace)
//空格和指定符號都不包含
else}}
/*** 返回文章中的字數
* @param
wordcount 文章內容
* @return
*/@suppresswarnings(
"unused")
private
intgetwordcount(string wordcontent)
else
if(wordcontent.length()==0
)else
for(
inti=0
;i<
wordcontent.length();i++)
if(num==2
)else}}
}if(!
bb)else}}
return
count;
}/**
* 根據條件來獲取文章的字元數
* @param
wordcontent 文章內容
* @param
compriseinterpunction 是否包含指定符號
* @param
comprisespace 是否包含空格
* @return
返回字元長度
*/public
intgetwordcharacter(string wordcontent,
boolean
compriseinterpunction,
boolean
comprisespace)
//不包含符號包含空格
elseif(
!compriseinterpunction
&&comprisespace)
//包含指定符號不包含空格
else
if(compriseinterpunction &&!
comprisespace)
//空格和指定符號都不包含
else
}/**
* 獲取文章中非空格的字元總數
* @param
wordcontent 文章內容
* @return
*/private
intgetnospacecount(string wordcontent)
else
if(wordcontent.length()==0
)else
return
spacecount;}}
java獲取文章的字數或者字元數
package util 獲取文章的字數或者字元數 author ffshi public class statwordcount 符號陣列 private final char chn 轉義符陣列 private final char space 空格的陣列 前半形,後全形 根據指定條件來篩選文章...
字數和字元數的區別是什麼
區別 字數 是指漢字的個數 而 字元數 是指漢字數 英文本母數 數字個數與標點數的總和。word文件中,乙個漢字或乙個全形字符 含標點 為2個字元,乙個半角字元 或標點 乙個空格均為1個字元。本教程操作環境 windows7系統,microsoft office word2019版本,dell g3...
如何檢視目錄下檔案的行或者字數等資訊
在linux下面我們有時候想知道我們乙個專案或者是乙個目錄下的所有檔案的行數以及字數 位元組數等資訊,有乙個命令就可一幫我們實現這個功能,那就是wc命令,下面我們來看看wc命令的使用 使用格式 wc 選項 檔案 選項 c 統計位元組數。l 統計行數。m 統計字元數。這個標誌不能與 c 標誌一起使用。...