| Previous | Contents | Index |
The ELEMENTS function returns the number of elements in a string expression that contains a list of elements. str_expr1 is the string containing the list of elements. str_expr2 is the separator. A comma is the default separator.
A given element is considered quoted only if the first non-blank character of the element is a single or double quote mark.
| Example 6-57 ELEMENTS function |
|---|
alphabet$ = 'a;b;c;d;e;f;g;h;i;j;k;l;m;n;o;p;q;r;s;t;u;v;w;x;y;z' print elements(alphabet$, ';') end 26 |
ELEMENT$ returns the element from str_expr1 which is specified by the num_expr. str_expr1 contains a set of elements with separators between them. The default separator is a comma:
| Example 6-58 ELEMENT$ function |
|---|
let a$ = element$('ADD,DEL,EXIT',2)
print a$
end
DEL
|
| Example 6-59 ELEMENT$ function - separators |
|---|
let sentence$ = 'This is a test.' let a$ = element$(sentence$,2,' ') print a$ end is |
The following example shows how having two commas [the default separator] in a row will cause the result to be nothing [null] for that particular element. |
| Example 6-60 ELEMENT$ function - separators |
|---|
let sentence$ = 'This,, is, a, test' print element$(sentence$, 2) end |
The ENCODE$ function returns a string containing a number converted to the base specified. num_expr is the value to convert. num_int is the base to convert. For instance, '2' indicates binary, etc. See also Section 6.9.1, DECODE(str_expr, int_expr)
| Example 6-61 ENCODE$ function |
|---|
do
input 'Enter a number to convert to hex': decnum
if decnum = 0 or _exit then exit do
print 'Hex for'; decnum;' is '; encode$(decnum,16)
loop
end
Enter a number to convert to hex? 34.56
Hex for 34.56 is 22
Enter a number to convert to hex? 255
Hex for 255 is FF
|
Given an expression and a format, FORMAT$ returns the result of the expression in the format indicated.
The '@' format character causes the character not to be translated by the formatter. The '<' and '>' are treated like an '@' character. You can justify a character string, but avoid zero suppression and zero insertion.
The FORMAT$ function takes an expression of any data type for the data to format (the first argument), including string expressions.
| Example 6-62 FORMAT$ function |
|---|
z$ = format$('1234567', '###~-####')
print 'Phone number: '; z$
end
Phone number: 123-4567
|
The FORMAT$ function returns all asterisks "*" in the case of overflow.
| Example 6-63 FORMAT$ function |
|---|
z$ = format$(12.23,'#.##') print z$ end **** |
FORMAT$() returns the same string data as given by the following:
PRINT USING str_expr: expr
|
The FORMAT$ function supports the DATE format and date arguments. Given a date in YYMMDD or CCYYMMDD format, FORMAT$ returns the date in the date format requested.
FORMAT$(z$, '{DATE [argument]}?')
|
The ? can be replaced with a mask. If no date argument is provided, the default is MDCY.
| Example 6-64 DATE format with FORMAT$ |
|---|
z1$ = format$('990122', '{date mdcy}?')
z2$ = format$('990122', '{date mdcy}##/##/####')
z3$ = format$('20000122', '{date mdcy}?')
z4$ = format$('20000122', '{date mdcy}##/##/####')
print z1$, z2$
print z3$, z4$
end
01221999 01/22/1999
01222000 01/22/2000
|
| DATE Argument |
YYMMDD Input |
Result | CCYYMMDD Input |
Result |
|---|---|---|---|---|
| none | 990207 | 02072000 | 20000207 | 02072000 |
| YMD | 990207 | 990207 | 20000207 | 990207 |
| CYMD | 990207 | 20000207 | 20000207 | 20000207 |
| MDY | 990207 | 022199 | 20000207 | 022199 |
| MDCY | 990207 | 02072000 | 20000207 | 02072000 |
| DMY | 990207 | 070299 | 20000207 | 070299 |
| DMCY | 990207 | 07022000 | 20000207 | 07022000 |
| DMONY | 990207 | 07-Feb-99 | 20000207 | 07-Feb-99 |
| DMONCY | 990207 | 07-Feb-2000 | 20000207 | 07-Feb-2000 |
| MONTHDY | 990207 | February 7, 99 | 20000207 | February 7, 99 |
| MONTHDCY | 990207 | February 7, 2000 | 20000207 | February 7, 2000 |
The FORMAT$ function supports character rotation. The ROTATE option rotates the last nn characters of a string to the first position in the string.
FORMAT$(z$, '{ROTATE n}?')
|
The ? can be replaced with a mask.
The GETSYMBOL$ function is used to return script variables and symbols. These can be the results of an HTML form submission, CGI environment variables, SheerPower symbols, DNS symbols, operating system symbols, or any variable you have defined as a symbol.
The GETSYMBOL$ function has an optional parameter that allows you to not trim the leading and trailing spaces of a symbol returned. The default parameter is set to TRUE. "True" is implied and means that the leading and trailing spaces will be trimmed. The FALSE parameter can be used if you do not want the leading and trailing spaces trimmed from the symbol retrieved.
| Example 6-65 GETSYMBOL$ function - SheerPower Symbol & Trimming Option |
|---|
set system, symbol 'test': value ' hi there'
print '<';getsymbol$('sp:test');'>'
print '<';getsymbol$('sp:test', false);'>'
print '<';getsymbol$('sp:test', true);'>'
<hi there>
< hi there>
<hi there>
|
Below are a few more examples of GETSYMBOL$:
| Example 6-66 GETSYMBOL$ function - HTML form submission |
|---|
// print the contents of the symbol "city" from a HTML form submit.
print getsymbol$('city')
|
| Example 6-67 GETSYMBOL$ function - CGI Environment Symbol |
|---|
// print the contents of the environment symbol REMOTE_ADDR
print getsymbol$('env:REMOTE_ADDR')
|
| Example 6-68 GETSYMBOL$ function - Operating System Symbol |
|---|
// print the contents of the operating system symbol PATH
print getsymbol$('os:PATH')
// and list the contents of the TEMP directory
print getsymbol$('os:TEMP')
C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\WINDOWS\sys
tem32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\ABSOLU~1;C:\Program Files\
QuickTime\QTSystem\;C:\Program Files\IDM Computer Solutions\UltraEdit\;C:\Progra
m Files\IDM Computer Solutions\UltraCompare;.
C:\DOCUME~1\User\LOCALS~1\Temp
|
Below is a list of symbol prefixes supported:
| Symbol Prefix | Description |
|---|---|
| env: | CGI environment variables (see Section 19.3.8, Summary of CGI Environment Variables) |
| os: | Operating system symbols. If the symbol begins with a \ then it is a registry symbol. |
| sp: | SheerPower symbols (see Section 11.14.15, SET SYSTEM, SYMBOL: VALUE ) |
| dns: | DNS symbols (see Section 11.14.14, Performing DNS Lookups with ASK SYSTEM, SYMBOL ) |
| Previous | Next | Contents | Index |