字符統(tǒng)計(jì)功能模塊
復(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é)果也不太一樣,原因是如何理解何為“有效字符”