-
Does anyone with VB6 have the exact syntax of the Split() function? I'm getting a bit pi**ed off with VB5's lack, so I thought I'd have a go at hacking my copy of VB and adding some stuff into it. I've already written a replacement (back in the days of VB4), and thought I'd put it in.
-
Code:
Split(ByVal sIn As String, Optional sDelim As String, Optional nLimit As Long = -1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As Variant
-
The whole thing
Code:
Public Function Split(ByVal sIn As String, Optional sDelim As String, Optional nLimit As Long = -1, Optional bCompare As VbCompareMethod = vbBinaryCompare) As Variant
Dim sRead As String, sOut() As String, nC As Integer
If sDelim = "" Then
Split = sIn
End If
sRead = ReadUntil(sIn, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(sIn, sDelim)
Loop While sRead <> ""
ReDim Preserve sOut(nC)
sOut(nC) = sIn
Split = sOut
End Function
-
Thanks, both of you. Kedaman - thanks for the code, but I already have one! (although I may dissect it in the traditional way...)
-
Kedaman, you code requires another function called ReadUntil otherwise you'll get an error.
Code:
Public Function ReadUntil(ByRef sIn As String, sDelim As String, Optional bCompare As VbCompareMethod = vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, sIn, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(sIn, nPos - 1)
sIn = Mid(sIn, nPos + Len(sDelim))
End If
End Function
-
Ok ok, i'm sure there are better Split functions, posted somewhere, or parksie could show us something
-
Again!
I can't seem to help myself. Everytime i see the word Split() i must post a reply.;)
Fast Split
-
That's the one i was talking about :)