当前位置: 首页 > 图文教程 > 脚本技术 > VBScript > vbs 字符统计功能模块

VBScript
VBS中SendKeys的基本应用
VBScript教程 第十四课在VBScript中使用对象
VBScript教程 第十三课 VBScript与窗体
VBScript教程 第十二课VBScript页面的简单样例
VBScript教程 第十一课深入VBScript
VBScript教程 第十课 VBScript编码约定
VBScript教程 第九课VBScript过程
VBScript教程 第八课 使用循环语句
VBScript教程 第七课使用条件语句
VBScript教程 第六课VBScript运算符
VBscript教程 第五课 VBScript常数
VBScript教程 第四课VBScript变量
VBScript教程 第三课VBScript数据类型
VBScript教程 第二课在HTML页面中添加VBscript代码
VBScript教程 第一课什么是VBScript
VBScript的入门学习资料
VBScript语法速查及实例说明
MsgBox函数语言参考
VBS教程:正则表达式简介 -后向引用
VBS教程:正则表达式简介 -选择与编组

VBScript 中的 vbs 字符统计功能模块


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 126 ::
收藏到网摘: n/a

字符统计功能模块
复制代码 代码如下:

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 "字符总数:" & All & chr(13) & "有效字符:" & Sum & chr(13) & "汉字总数:" & c, 64, "字符统计"
End sub

TongJi()将上面代码保存为TongJi.vbs,在TongJi.vbs同目录下建立ok.txt文本文件,将你要统计的文本复制到ok.txt中,运行TongJi.vbs即可以统计字数,与word的功能一样。不过算法不一样,结果也不太一样,原因是如何理解何为“有效字符”