【发布时间】:2015-08-05 23:13:40
【问题描述】:
如何将 Base64 编码字符串转换为带破折号的十六进制编码字符串(基本上为 uuid 格式)?
例如,如果我有
'FWLalpF2T5mmyxS03Q+hNQ0K'
那我怎么转换成:
1562da96-9176-4f99-a6cb-14b4dd0fa135
【问题讨论】:
-
可以使用
String#unpack(m用于 Base64 和H用于十六进制字符串)+Array#join添加-。 -
但是如何按照 uuid 模式拆分字符串?
-
Each directive may be followed by a number, indicating the number of times to repeat with this directive.例如"H8H4" 将base64 de编码的字符串解包到["1562da96", "9167"]。