Tokenize a string: Difference between revisions

Line 248:
There are built in libraries for tokenising strings, illustrated below, along with code that the user could create for the task.
 
First show somethe usesuse of thesysparse_string builtto inbreak procedureup a string and make a list of sys_parse_stringstrings.
 
;;; Make a list of strings from a string using space as separator
lvars list;
sysparse_string('the cat sat on the mat') -> list;
;;; print the list of strings
list =>
** [the cat sat on the mat]
 
By giving it an extra parameter 'true' we can make it recognize numbers and produce a list of strings and numbers
 
lvars list;
sysparse_string('one 1 two 2 three 3 four 4', true) -> list;
;;; print the list of strings and numbers
list =>
** [one 1 two 2 three 3 four 4]
;;; check that first item is a string and second an integer
isstring(list(1))=>
** <true>
isinteger(list(2))=>
** <true>
 
Now show some uses of the built in procedure sys_parse_string, which allows more options:
 
;;; Make pop-11 print strings with quotes