要不要严格按照位置来计算,如
34 d5 a9 f0 00
这种的按你图片中没有空格后的字符串为
34d5a9f0000
直接搜索字串,包含 4d ,算不是符合你的要求?
一、如果符合你的要求,
使用 替换函数 ,替换为空白,然后(前面的长度-后面的长度)/2
二、如果不符合你的要求
把字符串,按16进制转换为数值,保存到 byte 数组 里,
然后循环搜索整个数组计数。
'**************方法二******************* 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 '后面的查找就不写了。循环比较就是了。