excel vba解析每行4个字节的长数字串 [英] excel vba parse long number string into 4 bytes per row
本文介绍了excel vba解析每行4个字节的长数字串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很长的十六进制字符串,没有分隔符。我想创建一个按钮并将长行(A1)转换为数字4长(字节)的行,并使用接下来的4个数字填充下一个空行。字符串长度似乎是常量@ 522字符。
I have a long hex string with no delimiters. I would like to create a button and convert the long row (A1) into rows of numbers 4 long (byte) and populate the next free row with the next 4 numbers. String length appears to be a constant @ 522 char.
例如:"583031303A023A023A023A02620262026202620251025 ........"
Example : "583031303A023A023A023A02620262026202620251025........"
5830
3130
03a0 ...
抬头
推荐答案
多种方式中的一种 -
One of many ways -
Sub test()
Dim i As Long, j As Long
Dim n As Long, q As Long
Dim s As String, t As String
Dim arr() As String
For i = 1 To 24
s = s & Chr(64 + i)
Next
n = Len(s)
q = Int((n - 1) / 4)
ReDim arr(0 To q, 0 To 1) As String
For i = n To 1 Step -1
j = j + 1
t = Mid
(s ,我,1)& t
如果j = 4或i = 1那么
arr(q,0)= t
arr(q,1)= n - i + 1& "到" &安培; n - i - j + 2
j = 0
q = q - 1
t =""
结束如果
下一个
对于i = 0到UBound(arr)
Debug.Print arr(i,0),arr(i,1)
下一个
范围(" A1")。调整大小(UBound(arr)+ 1,2)= arr
结束子
(s, i, 1) & t If j = 4 Or i = 1 Then arr(q, 0) = t arr(q, 1) = n - i + 1 & " to " & n - i - j + 2 j = 0 q = q - 1 t = "" End If Next For i = 0 To UBound(arr) Debug.Print arr(i, 0), arr(i, 1) Next Range("A1").Resize(UBound(arr) + 1, 2) = arr End Sub
Peter Thornton
Peter Thornton
>
这篇关于excel vba解析每行4个字节的长数字串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文