how would i be able to parse a string like this:
373 3 3 113 "hello there" "sup all" 4 4
into this:
373
3
3
113
hello there
sup all
4
4
Printable View
how would i be able to parse a string like this:
373 3 3 113 "hello there" "sup all" 4 4
into this:
373
3
3
113
hello there
sup all
4
4
Well if you have VB6 you can use the Split function with a " " as delimiter. If you have VB5, no such command.
But, tada, I have a VB5 Split function for you!
The code above was not written by me :( Alas, I do not know who the author was.Code:Public Function WordSplit(sWords As String, sDelim As String) As Variant
Dim sTemp As String
Dim vWords() As Variant
Dim n, nCount As Integer
nCount = 0
sTemp = sWords
Do
n = InStr(1, sTemp, sDelim)
ReDim Preserve vWords(nCount)
If n = 0 Then
vWords(nCount) = sTemp
Else
vWords(nCount) = Left$(sTemp, n)
If Right(vWords(nCount), 1) = sDelim Then
vWords(nCount) = Mid(vWords(nCount), 1, Len(vWords(nCount)) - 1)
End If
sTemp = Mid$(sTemp, n + 1)
End If
nCount = nCount + 1
Loop Until n = 0
WordSplit = vWords
End Function
Try this:
VB6 ONLY!!! (otherwise, maybe someone will post the split code for vb5)
Code:Sub SplitIt(MyStr As String)
Dim Splited
Splited = Split(MyStr, " ")
For i = LBound(Splited) To UBound(Splited)
Debug.Print TrimQuotes(Splited(i))
End If
End Sub
Function TrimQuotes(String1 As String) As String
Dim FirstChr As String
Dim LastChr As String
FirstChr = Left(String1, 1)
LastChr = Right(String1, 1)
If FirstChr = Chr(34) And LastChr = Chr(34) Then
TrimQuotes = Mid(String1, 2, Len(String1) - 1)
Else
TrimQutoes = String1
End If
End Sub
I See someone did post the VB5 Split Function!!! Before Me!!!
(I haven't tested my trim quotes function, but it should work)
naa, thats not gonna work...
i need to parse out the first 4 strings then parse out the words in ""s, but at the same time keeping there spacing, and then parse out the last 2 strings so that it comes out as:
373
3
3
113
hello there
sup all
4
4