使用 MS excel - 使用类似于 0x80808080800180808080808080808080
的 34 个字符长度的字符串 - 需要转换为类似于 80 80 80 80 80 01 80 80 80 80 80 80 80 80 80 的字符串80
- 即去掉开头的 0x
并在原始字符串的每两个字符之间添加一个空格。
第一部分很好 - REPLACE(A1,1,2,"")
做到了。
需要第二部分的帮助。
更新:-
@Jeeped 的基于 UDF 的解决方案的回答 below有效 - 但需要非 UDF 解决方案。
最佳答案
尝试这个用户定义的函数。
Option Explicit
Function spaceBigHex(str As String, _
Optional delim As String = " ")
Dim i As Long, var As Variant
'strip off the 0×
str = Mid(str, 3)
'insert spaces from right to left
For i = Len(str) - 2 To 2 Step -2
str = Left(str, i) & delim & Mid(str, i + 1)
Next i
spaceBigHex = str
End Function
这也可以通过一系列 native 工作表 REPLACE 来完成提供静态字符串长度的函数。
=REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(RIGHT(A3, LEN(A3)-2),
31, 0, " "), 29, 0, " "), 27, 0, " "), 25, 0, " "), 23, 0, " "),
21, 0, " "), 19, 0, " "), 17, 0, " "), 15, 0, " "), 13, 0, " "),
11, 0, " "), 9, 0, " "), 7, 0, " "), 5, 0, " "), 3, 0, " ")
换行只是为了帮助您理解它。留下它们或移除它们;闻一闻并不重要。
1 用户定义函数(又名 UDF)被放入标准模块代码表中。点击 Alt+F11,当 VBE 打开时,立即使用下拉菜单插入 ► 模块(Alt+I,M)。将函数代码粘贴到标题为 Book1 - Module1 (Code) 的新模块代码表中。点击 Alt+Q 返回到您的工作表。
关于excel - 在字符串中每n个字符后插入一个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39050215/