1

我想分割字节字符串,例如AAFF10DC,用空格,所以它变成AA FF 10 DC.

如何在 AutoIt (v3) 中执行此操作?

4

3 回答 3

2

我想分割字节串……用空格……

使用示例StringRegExpReplace()

Global Const $g_sString  = 'AAFF10DC'
Global Const $g_sPattern = '(.{2})'
Global Const $g_sReplace = '$1 '
Global Const $g_sResult  = StringRegExpReplace($g_sString, $g_sPattern, $g_sReplace)

ConsoleWrite($g_sResult & @CRLF)

退货AA FF 10 DC

于 2018-05-15T14:54:27.767 回答
1

这有点难看,但它有效:

$string = "AAFF10DC"

$strArray = StringSplit($string, "") ; No delimiter will separate all chars.

$strResult = ""

If IsEvenNumber($strArray[0]) Then

    For $i = 1 to $strArray[0] Step 2
        $strResult = $strResult & $strArray[$i] & $strArray[$i+1] & " "
    Next

    MsgBox(0, "Result", $strResult)

Else
    MsgBox(0, "Result", "String does not contain an even number of characters.")
EndIf

Func IsEvenNumber($num)
    Return Mod($num, 2) = 0
EndFunc
于 2010-06-04T03:20:58.763 回答
1
Global $s_string = "AAFF10DC"
MsgBox(64, "Info", _str_bytesep($s_string))

Func _str_bytesep($s_str, $s_delim = " ")
    If Not (Mod(StringLen($s_str), 2) = 0) Then Return SetError(1, 0, "")
    Return StringRegExpReplace($s_str, "(..(?!\z))", "$1" & $s_delim & "")
EndFunc

只是另一种方法。对于大量的字节数据,我不建议使用这种方法。

于 2010-06-05T21:24:12.090 回答