work with strings

New to FreeBASIC? Post your questions here.
Post Reply
1134i
Posts: 62
Joined: Jun 05, 2005 4:39
Location: Vladivostok, Russia
Contact:

work with strings

Post by 1134i »

(sorry for my english)

in Visual Basic, i can write there

dim buf as string, outbut() as string
buf = "hello,bye"
outbuf = split(buf,",")

[in some languages: out = explode(",",buf); ]

can i get it in freebasic FAST (i.e. not MID$)?


also


in vb i can write here:

dim bytes() as byte, buf as string
buf = "mystring"
bytes = StrConv(buf,vbFromUnicode)

...
bytes(0) = "m", bytes(7) = "g"
it's very very faster, then mid$

can i get it in FreeBasic?

FBC v 0.13
1134i
Posts: 62
Joined: Jun 05, 2005 4:39
Location: Vladivostok, Russia
Contact:

no1

Post by 1134i »

Now i use my function:

Public Function SplitI(xMas As String, xDel As String, xRes() As String) As Long
ReDim xRes(0)
Dim nexti As Long, q As Long, lx As String * 1, lo As String * 1
lx = Left$(xDel, 1)
nexti = 0
For q = 1 To Len(xMas)
lo = Mid$(xMas, q, 1)
If lo = lx Then
nexti = nexti + 1: q = q + Len(xDel) - 1: ReDim Preserve xRes(nexti)
Else
xRes(nexti) = xRes(nexti) + lo
End If
Next q
SplitI = nexti
End Function


but it's slower, that native support... :(
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

In FB you can use string indexing, so no mid$ or strconv() are needed, i posted the split() function here: http://www.freebasic.net/forum/viewtopic.php?t=130.
Post Reply