I am trying following function from: viewtopic.php?t=13975 :
Code: Select all
Public Sub Split(Text As String, Delim As String = " ", Count As Long = -1, Ret() As String)
Dim As Long x, p
If Count < 1 Then
Do
x = InStr(x + 1, Text, Delim)
p += 1
Loop Until x = 0
Count = p - 1
ElseIf Count = 1 Then
ReDim Ret(Count)
Ret(0) = Text
Else
Count -= 1
End If
Dim RetVal(Count) As Long
x = 0
p = 0
Do Until p = Count
x = InStr(x + 1,Text,Delim)
RetVal(p) = x
p += 1
Loop
ReDim Ret(Count)
Ret(0) = Left(Text, RetVal(0) - 1 )
p = 1
Do Until p = Count
Ret(p) = Mid(Text, RetVal(p - 1) + 1, RetVal(p) - RetVal(p - 1) )
p += 1
Loop
Ret(Count) = Mid(Text, RetVal(Count - 1) + 1)
End Sub
Code: Select all
Dim As Long MaxCount
Dim As String s() , text , Delimiter
text = "enter the text to split"
MaxCount = -1
' if 2, second part will be whole text from second word onwards;
Delimiter = " "
split text, Delimiter, MaxCount, S()
print "length of s is: "; len(S)
for i as integer =0 to (len(s)-1)
print i; ": "; s(i)
next
Code: Select all
length of s is: 12
0: enter
1: the
2: text
3: to
4: split
5: ./rnfbc: line 2: 11167 Segmentation fault ./$1
Thanks for your help.