vbs 字符統(tǒng)計(jì)功能模塊
更新時間:2009年08月18日 01:51:17 作者:
TongJi()將上面代碼保存為TongJi.vbs,在TongJi.vbs同目錄下建立ok.txt文本文件,將你要統(tǒng)計(jì)的文本復(fù)制到ok.txt中,運(yùn)行TongJi.vbs即可以統(tǒng)計(jì)字?jǐn)?shù),與word的功能一樣。
字符統(tǒng)計(jì)功能模塊
Sub TongJi()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("ok.txt", 1)
strText = objFile.ReadAll
All = Len(strText)
S="` ~ ! @ # $ % ^ & * ( ) - _ = + \ | [ { ] } ; : ' , < . > / ? · ! ¥ ( ) 、 【 】 ; : ‘ ' “ ” , 《 。 》 ? …… —— chr(34) vbCrLf"
Signs=Split(S," ")
For Each Sign in Signs
strText = Replace(strText, "Sign", " ")
Next
objFile.Close
For k=1 To Len(strText)
tmpStr=Mid(strText, k, 1)
If Asc(tmpStr) > 127 Or Asc(tmpStr) < 0 Then
c = c + 1
tmpStr=" "
End If
Str = Str + tmpStr
Next
arrWords = Split(Str, " ")
For Each strWord in arrWords
If Len(strWord) > 0 Then
i = i + 1
End If
Next
Sum = c + i
msgbox "字符總數(shù):" & All & chr(13) & "有效字符:" & Sum & chr(13) & "漢字總數(shù):" & c, 64, "字符統(tǒng)計(jì)"
End sub
TongJi()將上面代碼保存為TongJi.vbs,在TongJi.vbs同目錄下建立ok.txt文本文件,將你要統(tǒng)計(jì)的文本復(fù)制到ok.txt中,運(yùn)行TongJi.vbs即可以統(tǒng)計(jì)字?jǐn)?shù),與word的功能一樣。不過算法不一樣,結(jié)果也不太一樣,原因是如何理解何為“有效字符”
復(fù)制代碼 代碼如下:
Sub TongJi()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("ok.txt", 1)
strText = objFile.ReadAll
All = Len(strText)
S="` ~ ! @ # $ % ^ & * ( ) - _ = + \ | [ { ] } ; : ' , < . > / ? · ! ¥ ( ) 、 【 】 ; : ‘ ' “ ” , 《 。 》 ? …… —— chr(34) vbCrLf"
Signs=Split(S," ")
For Each Sign in Signs
strText = Replace(strText, "Sign", " ")
Next
objFile.Close
For k=1 To Len(strText)
tmpStr=Mid(strText, k, 1)
If Asc(tmpStr) > 127 Or Asc(tmpStr) < 0 Then
c = c + 1
tmpStr=" "
End If
Str = Str + tmpStr
Next
arrWords = Split(Str, " ")
For Each strWord in arrWords
If Len(strWord) > 0 Then
i = i + 1
End If
Next
Sum = c + i
msgbox "字符總數(shù):" & All & chr(13) & "有效字符:" & Sum & chr(13) & "漢字總數(shù):" & c, 64, "字符統(tǒng)計(jì)"
End sub
TongJi()將上面代碼保存為TongJi.vbs,在TongJi.vbs同目錄下建立ok.txt文本文件,將你要統(tǒng)計(jì)的文本復(fù)制到ok.txt中,運(yùn)行TongJi.vbs即可以統(tǒng)計(jì)字?jǐn)?shù),與word的功能一樣。不過算法不一樣,結(jié)果也不太一樣,原因是如何理解何為“有效字符”
相關(guān)文章
VBS教程:函數(shù)-派生數(shù)學(xué)函數(shù)
VBS教程:函數(shù)-派生數(shù)學(xué)函數(shù)...2006-11-11
關(guān)于vbs WebBrowser導(dǎo)航問題
1、如何確定打開的新窗口的URL 2、如何使新窗口不彈出而是在原來頁面中顯示2008-05-05
VBS基礎(chǔ)篇 - vbscript class類的定義與使用
vbs Class就是聲明一個類的名稱,以及組成該類的變量、屬性和方法的定義,需要的朋友可以參考下2018-05-05
用VBS實(shí)現(xiàn)的批量gb2312轉(zhuǎn)utf-8,支持拖動
用VBS實(shí)現(xiàn)的批量gb2312轉(zhuǎn)utf-8,支持拖動...2007-10-10

