想统计一下文本中字符出现的次数,有什么好的思路
想统计一下文本中字符,每两个字符为一组,在文本出现了多少次?有什么好的算法思路?例如:
4d 出现了多少次?
5a 出现了多少次?
90 出现了多少次?
00 出现了多少次?
…………
文本内容截图如下:
'**************方法二******************* Dim s As String 's应该是文件或什么地方取值,这里只是示例 s = "4d5a90000300000004000000ffff0000b800000000000004000000000000000000000000000000000000000000000000000000000000e80000000e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f42062652072756e20696e20444f53206d6f64652e0d0d0a24000000000000c60ce8b5826d86e6826d86e6826d86e6ed1b2de6a76d86e6ed1b18e69b6d86e68b1515e6936d86e6826d87e6c46c86e6ed1b2ce6596d86e6ed1b1ce6836d86e6ed1b1be6836d86e652696368826d860000000000000000000000000000000000504500004c010500305b6c5900000000000000e00002010b010a000088070000d0020000000009ecb0600000000000a007000000400001000000200005000100000000005000100000000000900a000004000000000000200408100001000000000000010000010000000000001000000000000000007c550900b40000000f00900382e0000000000000000000000000000000200a009859000000000000000000000000000000000000000000000000185009004000000000000000000000a007000805000000000000000000000000000000000000002e7465787400000768607000010000008807000004000000000000000000000200000602e7264617461000018d1010000a0070000d201000080700000000000000000040000402e64617461" Dim a() As Byte Dim i As Long, j As String, o As Long '对半定义数组 o = Len(s) / 2 ReDim a(o) '循环取两个字符,十六进制字符串转数值保存到数组里 For i = 1 To o Step 2 j = Mid(s, i * 2 - 1, 2) a(i) = CByte("&H" & j) Next i '后面的查找就不写了。循环比较就是了。
[此贴子已经被作者于2022-1-9 12:23编辑过]