vb编程 输入一串字符,统计各个英文字母出现的次数,并统计出现字母的个数。求代码
展开全部
Function TotalString$(ByVal Text$)
Dim RegExp As Object, Matches As Object, Match As Object, tmp$, n%, Sum&
Set RegExp = CreateObject("VBScript.RegExp")
With RegExp
.Global = -1
.Pattern = "(.+)\1"
tmp = .Replace(Text, "$1")
.Pattern = "[abcdefghijkmlnoqprstuvwxyz]"
Set Matches = .Execute(tmp)
Sum = .Execute(LCase(Text)).Count
ReDim TotalData_Arr$(Matches.Count + 1)
For Each Match In Matches
.Pattern = Match
Set Matches = .Execute(LCase(Text))
TotalData_Arr(n) = Match & ": " & Matches.Count
n = n + 1
Next
TotalData_Arr(n) = "字母总数: " & Sum
TotalString = Join(TotalData_Arr, vbCrLf)
End With
End Function
Private Sub Form_Load()
MsgBox TotalString("This is a Test")
End
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询