StringFunctions

=String Manipulation Functions=

Run BASIC has several functions that work upon strings of text. These can be literal strings or string variables.

The syntax:

INSTR(a$, b$ [,i]) - Index of b$ in a$ with optional starting index i LEFT$(a$, i) - First i characters of a$ LEN(a$) - Count of characters in a$ LOWER$(a$) - a$ converted to lowercase MID$(a$, x [, y]) - Contents of a$ starting at x, with optional length y RIGHT$(a$, i) - Last i character from string a$ TRIM$(a$) - a$ without leading or trailing spaces UPPER$(a$) - a$ converted to uppercase WORD$(a$, n[, d$]) - nth word from a$ using whitespace as delimiter, with optional delimiter d$ > If an empty field is encountered between two delimiters, a delimiter is returned. > Example: If String$="1|2|3|4||6", WORD$(String$, 5, "|") would return "|"

Note that these functions return a value. They are not assignment statements. You cannot use MID$ to alter characters in a string, for instance.

Here is a program that demonstrates the use of the functions listed above.

code format="vbnet" var$ = "I love Run BASIC. "

print left$(var$, 4) print right$(var$,8) print lower$(var$) print upper$(var$) print mid$(var$,3,4) print trim$(var$) print word$(var$,3) print "Length of string is ";len(var$) print "First occurance of ""R"" is ";instr(var$,"R",1) code

The output from this program looks like this:

//I lo BASIC. i love run basic. I LOVE RUN BASIC. love I love Run BASIC. Run Length of string is 18 First occurance of "R" is 8//