4.06 SPLIT and JOIN

SPLIT

Function:

Splits a string using the specified delimiters and stores the result in an array.

Optionally it will call a user defined function that can make changes to each word before storing it in the array.

Syntax:

SPLIT string, words [, delimiters [, pairs]] [USE expr]

where:

string
the string to be split
words
the target array
delimiters
a list of characters that are to be used to split the string. If this is omitted the default is a space.
pairs
a string containing enclosing pairs of characters. Any delimiters found that are enclosed by any of the specified pairs will be ignored.
expr
the name of a function to be called to process each output string before storing it.

Example:

str = "/etc/temp/filename.ext"
split str, words, "/."
for each word in words
  put " [":word:"]"
  next

// displays:
[]
[etc]
[temp]
[filename]
[ext]

JOIN

Function:

Returns a specified string made up of each element of the array joined together.

Syntax:

JOIN words, string [, separator]

where:

words
the array containing the elements to be joined.
string
the target string
separator
the character to be used to separate each array element in the output string. If the separator is omitted it defaults to a space.

Example:

st = "/etc/temp/filename.ext"
split st, words, "/."
join words, st, "/"
put "[";s;"]"

// displays:
[/etc/temp/filename/ext]

lynplex/lp0406.txt · Last modified: 2011/09/08 16:07 (external edit)