How to realize the function of character Statistics in vbs
This article mainly shows you "vbs how to achieve character statistics function", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "vbs how to achieve character statistics function" this article.
Character statistics function module
The code is as follows:
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 Kitch1 To Len (strText)
TmpStr=Mid (strText, k, 1)
If Asc (tmpStr) > 127Or 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 "Total number of characters: & All & chr (13) &" valid characters: & Sum & chr (13) & "Total number of Chinese characters: & c, 64, character Statistics"
End sub
TongJi () save the above code as TongJi.vbs, create an ok.txt text file in the same directory as TongJi.vbs, copy the text you want to count to ok.txt, and run TongJi.vbs to count the number of words, just like word. However, the algorithm is different and the result is not the same. The reason is how to understand what is a "valid character".
The above is all the contents of the article "how to achieve character Statistics in vbs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!