background image
Original Author Paul Laughton, 2011
Page 66
De Re BASIC!
WORD$(<source_sexp>, <n_nexp> {, <test_sexp>})
This function returns a word from a string. The <source_sexp> string is split into substrings at each
location where <test_sexp> occurs. The <n_nexp> parameter specifies which substring to return;
numbering starts at 1. The <test_sexp> is removed from the result. The <test_sexp> parameter is an
optional Regular Expression; if it is not given, the source string is split on whitespace. Specifically, the
default <test_sexp> is "\s+".
Leading and trailing occurrences of <test_sexp> are stripped from <source_sexp> before it is split. If
<n_nexp> is less than 1 or greater than the number of substrings found in <source_sexp>, then an
empty string ("") is returned. Two adjacent occurrences of <test_sexp> in <source_sexp> result in an
empty string; <n_nexp> may select this empty string as the return value.
Examples:
string$ = "The quick brown fox"
result$ = WORD$(string$, 2); % result$ is "quick"

string$ = ":a:b:c:d"
delimiter$ = ":"
SPLIT array$[], string$, delimiter$ % array$[1] is ""
result$ = WORD$(string$, 1, delimiter$) % result$ is "a", not ""
This function is similar to the Split command. See Split for a note about Regular Expressions.
ENCODE$(<type_sexp>, {<qualifier_sexp>}, <source_sexp>)
Returns the string <source_sexp> encoded in one of several ways, as specified by the <type_sexp>. The
<qualifier_sexp> usage depends on the type:
Type
Qualifier
Default
Result
"ENCRYPT"
password
""
(empty)
Encrypts the source string using the password parameter.
The encryption algorithm is "PBEWithMD5AndDES". This
usage of ENCODE$() works the same way as the ENCRYPT
command. Use the DECODE$() function to decrypt.
"DECRYPT"
password
""
Same as type "ENCRYPT" (encrypts, does not decrypt).
"ENCRYPT_RAW" password
""
Same as type "ENCRYPT" except the input and output are
buffer strings. This is useful for encrypting binary data.
"DECRYPT_RAW" password
""
Same as "ENCRYPT_RAW" (encrypts, does not decrypt).
"URL"
charset
"UTF-8" Encodes the source string using the format required by
HTML
application/x-www-form-urlencoded
. You should
omit the charset parameter.
"BASE64"
charset
"UTF-8" Encodes the source string into the Base64 representation of
binary data. See RFCs
2045
and
3548
. The simplest way to
use this function is to omit the charset parameter.
The type is required, but see below for the two-parameter form of ENCODE$() and DECODE$().
The type IS NOT case-sensitive: "BASE64", "base64", and "Base64" are all the same.
The qualifier is optional, but its comma is required.