View Full Version : split counting
ksilenio
06-02-2020, 02:01 PM
Hi to everyone . I have a string like "String=Stri1-Stri2-Stri3" . I use the split (String,"-") and i have 3 strings, now, is there any method to get the number (for the example the number is 3) of the substrings from the split command?
Regards Kostas
Paul_Hossler
06-02-2020, 04:21 PM
Option Explicit
Sub test()
Dim s As String
Dim v As Variant
s = "Stri1-Stri2-Stri3"
v = Split(s, "-")
'sometimes people have Option Base 1 set, so this is safest way
MsgBox UBound(v) - LBound(v) + 1
End Sub
Sub M_snb()
msgbox ubound(split("String=Stri1-Stri2-Stri3","-"))+1
End Sub
ksilenio
06-04-2020, 12:03 PM
Thank you very much for your answers
jolivanes
06-05-2020, 10:55 PM
What doe you expect the answer to be if you have a string like "Stri7-Stri8-Stri9"? 3 or 9?
I understand it different.
Dim str As String
str = "Stri1-Stri2-Stri3"
MsgBox (Mid(Split(str, "-")(2), 5))
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.