0

我如何使用 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

非常感谢。

4

1 回答 1

0

VBA 具有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单元格中)。

于 2013-02-05T03:11:42.727 回答