如何使用excel或其他更简单的语言实现这一目标?
original data:
100301010100019743024000
after formatting:
100,3010,1,01,000,1974,3024,000
Segment 1 = 3 char
Segment 2 = 4 char
Segment 3 = 1 char
Segment 4 = 2 char
Segment 5 = 3 char
Segment 6 = 4 char
Segment 7 = 4 char
Segment 8 = 3 char
非常感谢。
答案 0 :(得分:0)
VBA拥有exactly this purpose的left()
,right()
和mid()
个功能。
执行此操作的功能类似于:
Function FmtStr (MyStr As String) As String
If Len (MyStr) <> 24 Then
FmtStr = "?"
Else
FmtStr = _
Mid (MyStr, 1, 3) + "," + _
Mid (MyStr, 4, 4) + "," + _
Mid (MyStr, 8, 1) + "," + _
Mid (MyStr, 9, 2) + "," + _
Mid (MyStr, 11, 3) + "," + _
Mid (MyStr, 14, 4) + "," + _
Mid (MyStr, 18, 4) + "," + _
Mid (MyStr, 22, 3)
End If
End Function
用以下方式调用:
MsgBox (FmtStr("100301010100019743024000"))
为您提供了一个对话框:
如果您只想在Excel公式中使用:
=concatenate(mid(a1,1,3), ",", mid(a1,4,4), ",", ... ",", mid(a1,22,3))
(假设原始字符串当然在A1
单元格中)。