String Functions

The table below describes commonly used string functions. See Help → Macro Functions by Category → String Functions for a complete list.

See also documentation for the parse Statement.

Function

Description

_str center (_str string ,int width [,-str pad_ch ])

Returns string padded evenly on left and right with spaces or a character you choose with the optional argument pad_ch.

_ dec2hex (long number [,int base ])

Returns number converted to base specified.

_str expand_tabs (_str string [,int start [,int count [,_str option ]]])

Very similar to substr function except that this function supports tab characters very well.

_str field(_str string ,int width )

Returns string padded with trailing spaces to width characters.

long hex2dec(_str number [,int base ])

Returns number converted to base specified.

_str indent_string(int width )

If indent with tabs is on, a string of tabs of length width is returned. Otherwise, a string of spaces of length width is returned.

boolean isalnum(_str ch )

Returns non-zero value if ch is a numeric or alphabetic character.

boolean isalpha(_str ch )

Returns non-zero value if ch is an alphabetic character.

boolean isdigit(_str ch )

Returns non-zero value if ch is a numeric character.

boolean isinteger(_str string )

Returns non-zero value if string is a valid int. If string is floating point number, 0 is returned.

boolean isnumber(_str string )

Returns non-zero value if string is a valid double (floating pointer number).

_str last_char(_str string )

Returns last character of string. If string is null, the space character is returned.

int lastpos(_str needle [,_str haystack [,int start [,_str options ]]])

Returns the position (1..length(haystack)) of the last occurrence of needle in haystack. If needle is not found, 0 is returned. Regular expressions are supported.

int length(_str string )

Returns the number of characters in string.

_str lowcase(_str string )

Returns string converted to lowercase.

_str number2onoff(_str number )

Returns off if number==0. Otherwise on is returned.

_str number2yesno(_str number )

Returns N if number==0. Otherwise Y is returned.

parse expr with template

Breaks apart the expression expr given into variables that appear in template, and much more. See parse Statement for more information.

boolean parseoption(_str & cmdline ,_str option_ch )

Strips + or - option from cmdline. Returns non-zero number if option_ch was found.

int pos(_str needle [,_str haystack [,int start [,_str options ]]])

Returns the position (1..length(haystack)) of the first occurrence of needle in haystack. If needle is not found, 0 is returned. Regular expressions are supported.

boolean setonoff(_str & name ,_str value )

Sets name to 1 or 0 corresponding to value=on or value=off. Returns 0 if input value is valid. Displays message if value is not on or off.

boolean setyesno(int & name ,_str value )

Sets name to 1 or 0 corresponding to value=Y,Yes or value=N,No. Returns 0 if input value is valid. Displays message if value is not Y or Yes, N or No.

_str stranslate(_str string , _str replace_string ,_str search_string , _str search_options )

Returns string with all occurrences of search_string replaced with replace_string.

_str strieq(_str string1 ,_str string2 )

Returns true if string1 matches string2 when case is ignored.

_str strip(_str string ,_str ltb [,_str strip_char ])

Returns string stripped of leading and/or trailing strip_char.

_str strip_filename(_str filename , 'P'|'D'|'E'|'N')

Returns filename with part stripped. P=Path, D=Drive, E=Extension, N=Name.

_str strip_last_word(_str & line )

Returns the last space delimited word in line. The last word and trailing spaces are deleted from line.

_str strip_options(_str cmdline ,_str & options )

Returns cmdline without words that start with the characters -, +, or [. options variable is set to stripped option words.

_str substr(_str string ,int start [,int length [,_str pad ]])

Returns length characters of string beginning at start. By default, length defaults to rest of string. If length is greater than length of string, the return string is padded with blanks or pad character if specified.

_str translate(_str string [,_str output_table [,_str input_table [,_str pad ]]])

Returns string with characters translated according to arguments.

_str upcase(_str string )

Returns string converted to uppercase.

int verify(_str string , _str reference [, M| [,int start ]])

Returns the position (1..length(string))of first character not matching or matching a character in reference. 0 is returned on failure.

_str word(_str string ,int Nth )

Returns the Nth space or tab-delimited word in string. Is returned if the Nth word does not exist.