Restored from previous forum. Originally posted by teachco.
Some statements like gettoken, nexttoken, ... would be useful.
They can split strings into tokens at certain positions (delimiter-string).
The delimiter-string is a set of characters, which define the positions, where the string will be cut.
Example:
source$ = "This is a text, we will split into substrings."
result$ = gettoken(source$," ,")
will generate the following results after 9 calls:
This
is
a
text
we
will split
into
strings
You can find these statements in JAVA. They are very useful for working with input-streams of any kind.
[Implemented] gettoken, nexttoken , ...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Stan.
Hi,
Wonder if your example would work even in JAVA ...
Hope this helps.
Stan
Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
Hi,
Wonder if your example would work even in JAVA ...
you can do it in PB :...
Example:
source$ = "This is a text, we will split into substrings."
result$ = gettoken(source$," ,")
will generate the following results after 9 calls:
This
is
a
text
we
will split
into
strings
You can find these statements in JAVA. They are very useful for working with input-streams of any kind.
Code: Select all
A$ = "this is a test"
Global A$
Procedure.s gettoken( B$, C$ )
len_B = Len( B$ )
posit = FindString( B$, C$, 1 )
If posit > 0
E$ = Left( B$, posit )
A$ = Right( A$, len_B - posit )
Else
E$ = B$
A$ = ""
EndIf
ProcedureReturn E$
EndProcedure
OpenConsole( )
While Len( A$ )
D$ = gettoken( A$, " " ) ;
PrintN( D$ )
Wend
Input( )
CloseConsole( )
Stan
Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> Some statements like gettoken, nexttoken, ... would be useful.
> They can split strings into tokens at certain positions (delimiter-string).
What do you need this for? I'm wondering if you're trying to parse the command
line arguments to your app? If so, use the ProgramParameter() command. If not,
I'll just shut up.
PB - Registered PureBasic Coder
> Some statements like gettoken, nexttoken, ... would be useful.
> They can split strings into tokens at certain positions (delimiter-string).
What do you need this for? I'm wondering if you're trying to parse the command
line arguments to your app? If so, use the ProgramParameter() command. If not,
I'll just shut up.
PB - Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
Its all in "StringLibraryEx" addon library
on Paul´s site: http://www.reelmediaproductions.com/pb/
commands: GetWord$() and CountWords_()
Very useful for a parser !!
Frederic:
maybe you can take a look and add
GetWord() and CountWords()
directly into PureBasic ??
I need this 2 commands too, and when its included
in PureBasic, its sure i can use it in the future.
(Maybe the addon lib doesnt work anymore, in future
version of PB)
cya,
...Danilo
(registered PureBasic user)
Its all in "StringLibraryEx" addon library
on Paul´s site: http://www.reelmediaproductions.com/pb/
commands: GetWord$() and CountWords_()
Very useful for a parser !!
Frederic:
maybe you can take a look and add
GetWord() and CountWords()
directly into PureBasic ??
I need this 2 commands too, and when its included
in PureBasic, its sure i can use it in the future.
(Maybe the addon lib doesnt work anymore, in future
version of PB)
cya,
...Danilo
(registered PureBasic user)