使用vbs腳本統計某幾個詞出現在txt檔案中的次數并輸出
uj5u.com熱心網友回復:
用RegExp+Dictionary可解決;uj5u.com熱心網友回復:
接二樓,正則運算式和字典就可以了。具體代碼如下,比如我查找字串中連續的3個數字,然后放到一個陣列里面,陣列的數量就是個數啦。
str ="測驗資料其中有123,看能不能找234出這段456話中的連777續3個數字!"
Pattern ="\d{3}"
MsgBox(str)
msg=RegExpGeneral(str,Pattern)
For Each i In msg
If IsEmpty(i) Then
Exit For
End If
MsgBox i
Next
Function RegExpGeneral(TextValue,Pattern)
Dim i
Set RegExpGen = New RegExp
With RegExpGen
.Global = True
'設定Global適用性
.IgnoreCase = True
'設定實體的不靈敏性
.Pattern = Pattern
'模式
Set Matches = .Execute(TextValue)
'執行搜索正則 即形成了陣列物件
End With
'定義一個動態陣列,來確定其回傳的結果長度
Dim MyArraysLenth
ReDim MyArraysLenth(Matches.Count)
For i = 0 To Matches.Count-1
MyArraysLenth(i) = Matches(i).Value
Next
RegExpGeneral = MyArraysLenth
End Function
uj5u.com熱心網友回復:
感謝感謝,問題已經解決轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/27116.html
標籤:vbScript
上一篇:一段奇怪的js代碼解密
下一篇:關于VSCode學習WEB問題
