我有一个字符串
“1。这应该是一个原因.2。这是一个解决方案。想要寻找更多?3。代码是234123.4.end of solution。”
我希望将它拆分为一个n数组中的“1.这应该是一个原因”然后“2.这是一个解决方案。想要寻找更多?”那么“3.code是234123”。等等,
我尝试的代码如下:
Dim myString As String
myString = "1.This should be a cause.2.this is a solution.Want to look for more? 3.code is 234123.4.end of solution."
Dim solArr As Variant
Dim i As Integer
Dim solText As String
solArr = Split(myString, ".")
For i = 2 To UBound(solArr)
solText = Mid(myString, InStr(1, myString, i - 1 & "."), InStr(1, myString, i & ".") - 1)
Next
答案 0 :(得分:2)
Sub test()
Dim myString As String
myString = "1.This should be a cause.2.this is a solution.Want to look for more? 3.code is 234123.4.end of solution."
Dim i As Long
i = 2
myString = Mid(Trim(myString), 3)
While InStr(myString, i & ".")
myString = Replace(myString, i & ".", "///", 1, 1)
i = i + 1
Wend
Dim solArr As Variant
solArr = Split(myString, "///")
For i = 0 To UBound(solArr)
solArr(i) = i + 1 & ". " & Trim(solArr(i))
Next
End Sub