提取4个部分的字符串

时间:2017-04-10 15:00:12

标签: vba

我有以下字符串:

21||10/04/2017||34390136||SOME TEXT

如何在vba中提取四个值除以" ||" ? (21,10/04 / 2017,34390136,Some Text)

我需要每个值都有四个字符串。

由于

1 个答案:

答案 0 :(得分:1)

使用SPLIT命令按分隔符分割:

Sub Test()

    Dim MyString As String
    Dim MySplit As Variant
    Dim x As Long

    MyString = "21||10/04/2017||34390136||SOME TEXT"
    MySplit = Split(MyString, "||")

    For x = LBound(MySplit) To UBound(MySplit)
        MsgBox MySplit(x)
    Next x

End Sub

或单行:
split("21||10/04/2017||34390136||SOME TEXT","||")(0)
split("21||10/04/2017||34390136||SOME TEXT","||")(1)
split("21||10/04/2017||34390136||SOME TEXT","||")(2)
split("21||10/04/2017||34390136||SOME TEXT","||")(3)