[Implemented] gettoken, nexttoken , ...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] gettoken, nexttoken , ...

Post by BackupUser »

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.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Stan.

Hi,

Wonder if your example would work even in JAVA ...
...
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.

you can do it in PB :

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( )

Hope this helps.

Stan


Since I attended an MS course, my programs no longer have bugs ... just hidden "features" !! [ PB. registered user ]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by teachco.
Hi,

Wonder if your example would work even in JAVA ...
You're absolutly right. The code is NOT Java, but "gettoken" and nexttoken".

Thank you for the help.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

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)
Post Reply