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. MySQL中CHAR和VARCHAR的区别
  2. VB6拾遗:轻量级COM对象
  3. JavaScript的Trim函数有12种写法,你可知道么?
  4. HTML,Unicode与NCR(数字字符引用)
  5. Chrome用 –proxy-server 设置代理服务器

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

  1. wakaka说道:

    更正为a~f的词频。

留下回复