Could someone please tell me what the VB equivalent of the ASP 'Split' function is?
A VB function would work if that is more convinient
Printable View
Could someone please tell me what the VB equivalent of the ASP 'Split' function is?
A VB function would work if that is more convinient
Code:'split function for VB5 and under vb6 has the function
'posted originally by Aaron Yount
Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
'Example:
Private Sub Form_Load()
Dim vLines As Variant
Dim lLine As Long
vLines = Split2("Line1,Line2,Line3", ",")
For lLine = 0 To UBound(vLines)
List1.AddItem vLines(lLine)
Next
End Sub