小编OSY*_*OSY的帖子

搜索字符串在文本文件中出现的次数

我正在尝试阅读文本文件并计算文本文件中出现短语/字符串(不是单词)的次数,但到目前为止我所拥有的是:

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("D:\VBscript project\testing.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close

i = 0

arrLines = Split(strContents, "")

For Each strLine in arrLines
    If InStr(strLine, "hi there") Then
        i = i + 1
    End If
Next

WScript.Echo "Number of times word occurs: " & i
Run Code Online (Sandbox Code Playgroud)

这只会让我计算一个单词出现的次数,当我尝试调整它来计算短语时,这不起作用。

string vbscript

4
推荐指数
1
解决办法
4445
查看次数

标签 统计

string ×1

vbscript ×1