How to split a string into a fixed length string array?

前端 未结 8 1863
别跟我提以往
别跟我提以往 2020-12-21 02:10

I have a long string like this

dim LongString as String = \"123abc456def789ghi\"

And I want to split it into a string array. Each element

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 02:37

    This is my solution:

    Function splitN(str As String, n As Integer) As String()
      For i = 0 To Len(str) Step n + 1
        Try
          str = str.Insert(i + n, "|")
        Catch
        End Try
      Next
      Return str.Split("|")
    End Function
    

    You can call it like: splitN("abc123def456frg987ef", 3)

提交回复
热议问题