Split() and Join()
- the.weavster
- Addict
- Posts: 1576
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
Split() and Join()
myArray = Split(myString, myDelimiter)
myString = Join(myArray, myDelimiter)
I can't find these in the help file but I guess they may already exist.
myString = Join(myArray, myDelimiter)
I can't find these in the help file but I guess they may already exist.
Re: Split() and Join()
For splitting, look up "StringField" in the manual.
For joining, nothing like that yet exists.
For joining, nothing like that yet exists.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
> For splitting, look up "StringField" in the manual.
Haha, he wants to split arrays, not strings...
PureBasic is not a scripting language like perl or PHP. Nevertheless, there are very powerful functions in perl, that I would like to see in PB.
Haha, he wants to split arrays, not strings...

PureBasic is not a scripting language like perl or PHP. Nevertheless, there are very powerful functions in perl, that I would like to see in PB.
PB 4.30
Code: Select all
onErrorGoto(?Fred)
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
what should "Join" do, anyhoff?
or something like that:
Code: Select all
a$ = "Bla"
b$ = "Blub"
c$ = " "
d$ = a$ + b$ + c$
Code: Select all
Dim Field.s(9)
;...
Out.s = ""
For n=0 to 9
Out + Field(n)
Next
oh... and have a nice day.
for those who are interested :
http://www.purebasic.fr/english/viewtopic.php?t=21495
since it is possible in pb4 to pass an array or a linkedlist to a procedure, such features are easy to program.
http://www.purebasic.fr/english/viewtopic.php?t=21495
since it is possible in pb4 to pass an array or a linkedlist to a procedure, such features are easy to program.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
> Haha, he wants to split arrays, not strings
What's so funny? His requested syntax is...
myArray = Split(myString, myDelimiter)
...which looks like he wants to create an array ("MyArray") from "MyString".
So if "MyString" was "a/b/c/d/e" and the delimiter was "/" then his requested
command would create an array of MyArray(1)="a", MyArray(2)="b", etc.
What's so funny? His requested syntax is...
myArray = Split(myString, myDelimiter)
...which looks like he wants to create an array ("MyArray") from "MyString".
So if "MyString" was "a/b/c/d/e" and the delimiter was "/" then his requested
command would create an array of MyArray(1)="a", MyArray(2)="b", etc.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Code: Select all
Procedure Split(S.s, Delimiter.s, Array.s(1))
Protected I
Protected C = CountString(S, Delimiter)
For I = 0 To C
Array(I) = StringField(S, I+1, Delimiter)
Next
ProcedureReturn C
EndProcedure
Procedure.s Join(Delimiter.s, Count.l, Array.s(1))
If Count
ProcedureReturn Join(Delimiter, Count-1, Array()) + Delimiter + Array(Count)
Else
ProcedureReturn Array(0)
EndIf
EndProcedure
Dim MyArray.s(10)
Test.s = "Jackdaws love my big sphinx of quartz."
C = Split(Test, " ", MyArray())
For I = 0 To C
Debug MyArray(I)
Next
Debug "-----"
Debug Join(" ", C, MyArray())
- the.weavster
- Addict
- Posts: 1576
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
Is looping the only way?
In REALbasic the equivalent to StringField() is NthField(). If you use NthField() and a loop to create your own array from a large block of delimited text it can take an inordinate amount of time to complete, maybe even make the program stop responding.
However Split() does the job in the blink of an eye.
I thought maybe there was something cleverer going on.
In REALbasic the equivalent to StringField() is NthField(). If you use NthField() and a loop to create your own array from a large block of delimited text it can take an inordinate amount of time to complete, maybe even make the program stop responding.
However Split() does the job in the blink of an eye.
I thought maybe there was something cleverer going on.