加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb6 – 计算字符串中字符的出现次数

发布时间:2020-12-17 00:08:58 所属栏目:大数据 来源:网络整理
导读:寻找在VB6中执行此操作的最佳方法.通常,我会使用这种方法…… ' count spaces For i = 1 To Len(text) If Mid$(text,i,1) = " " Then count = count + 1 Next 我会使用修改后的桶排序: Dim i as IntegerDim index As IntegerDim count as IntegerDim FoundB
寻找在VB6中执行此操作的最佳方法.通常,我会使用这种方法……
' count spaces
    For i = 1 To Len(text)
        If Mid$(text,i,1) = " " Then count = count + 1 
    Next
我会使用修改后的桶排序:
Dim i as Integer
Dim index As Integer
Dim count as Integer
Dim FoundByAscii(0 To 255) As Boolean
For i = 1 To Len(text)
    index = Asc(Mid$(text,1))
    FoundByAscii(index) = True
Next i
count = 0
For i = 0 To 255
    If FoundByAscii(i) Then
        count = count + 1
    End If
Next i

……而且你的结果是有价值的.性能是O(N) – 如果Mid $是O(1).

编辑:

根据您的澄清,执行以下操作:

' count spaces
    Dim asciiToSearchFor As Integer
    asciiToSearchFor = Asc(" ")
    For i = 1 To Len(text)
        If Asc(Mid$(text,1)) = asciiToSearchFor Then count = count + 1 
    Next

因为ascii比较必须比字符串比较更快.为了以防万一,我会对其进行分析,但我很确定.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读