用定界符拆分一串十六进制值

Splitting a string of hex values with delimiter

我有一串十六进制值:-

ffffe7ba2cffffe7c52cffffe7c22cffffe7c12cffffe7c82cffffe7c62cffffe7b52cffffe7a02c

我想使用分隔符值 "2c".

拆分此字符串

我尝试使用 .split(0x2c).split("2c").split(b'\x2c'),但 none 似乎有效。

有什么建议吗?

谢谢。

您使用的是哪个 Python 版本?

在 Python 3.7 中,以下代码似乎有效:

tmp = "ffffe7ba2cffffe7c52cffffe7c22cffffe7c12cffffe7c82cffffe7c62cffffe7b52cffffe7a02c"
tmp.split("2c")

Out[37]: 
['ffffe7ba',
 'ffffe7c5',
 'ffffe7c2',
 'ffffe7c1',
 'ffffe7c8',
 'ffffe7c6',
 'ffffe7b5',
 'ffffe7a0',
 '']

或者您想要的输出是什么?

对我来说效果很好。

In [1]: s = "ffffe7ba2cffffe7c52cffffe7c22cffffe7c12cffffe7c82cffffe7c62cffffe7b52cffffe7a02c"
In [2]: s.split("2c")
Out[2]: 
['ffffe7ba',
 'ffffe7c5',
 'ffffe7c2',
 'ffffe7c1',
 'ffffe7c8',
 'ffffe7c6',
 'ffffe7b5',
 'ffffe7a0',
 '']

我猜你需要这样的东西:

myHex = 0xffffe7ba2cffffe7c52cffffe7c22cffffe7c12cffffe7c82cffffe7c62cffffe7b52cffffe7a02c
myStringForHex = str(hex(myHex))[2:]
myStringForHex.split('2c')

对应的输出为:

['ffffe7ba',
 'ffffe7c5',
 'ffffe7c2',
 'ffffe7c1',
 'ffffe7c8',
 'ffffe7c6',
 'ffffe7b5',
 'ffffe7a0',
 '']