VBS统计字符串全部字符出现的次数并排序

标签: , , , ,

我们知道,霍夫曼编码的基础是进行词频统计。然后依据统计数据,构建霍夫曼树,进而得到霍夫曼编码表。利用霍夫曼编码表,就可以进行压缩工作了。这里,用VBS来写一个字符串的词频统计,统计0~9,a~z的词频并排序。

Public Function cnt(str,x)
    str = UCase(str)
    x = UCase(x)
    cnt = UBound(Split(str,x))
End Function

Dim a(15,1),i,j,k,l

str = "0123456789abcdef2222222aaaaabbbcc"

For i =  & h0 To & hf
    a(i,0) = Hex(i)
    a(i,1) = cnt(str,Hex(i))
Next

For l = 0 To UBound(a)
    data = data & "未排序结果为:" & a(l,0) & "出现次数" & a(l,1) & vbLf
Next
MsgBox data
data = ""

For j = 0 To 15
    For k = j To 15
        If a(j,1) < a(k,1)Then
            tmp1 = a(j,1)
            a(j,1) = a(k,1)
            a(k,1) = tmp1
            tmp2 = a(j,0)
            a(j,0) = a(k,0)
            a(k,0) = tmp2
        End If
    Next
Next

For l = 0 To UBound(a)
    data = data & "排序后结果为;" & a(l,0) & "出现次数" & a(l,1) & vbLf
Next
MsgBox data
data = ""

原文链接:http://think2think.cn/archives/282/

随机文章:

  1. VBS真的能实现多线程?
  2. MySQL字符集与排序方式
  3. TLI.TLIApplication,被遗忘的COM组件
  4. cURL 7.22.0 with zlib SSL and IPv6 support
  5. ActivePython PyPM error: (OperationalError) unable to open database file None None

一条评论 发表在“VBS统计字符串全部字符出现的次数并排序”上

  1. wakaka说道:

    更正为a~f的词频。

留下回复