Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
BASIC String Operators
◄Expressions and Operators► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
String Operators
A string expression consists of string constants, string variables, and
other string expressions combined by string operators. There are two
classes of string operations: concatenation and string comparison.
The act of combining two strings is called concatenation. The plus symbol
(+) is the concatenation operator for strings. For example, the following
program fragment combines the string variables A$ and B$ to produce the
value FILENAME:
A$ = "FILE": B$ = "NAME"
PRINT A$ + B$
PRINT "NEW " + A$ + B$
Output
FILENAME
NEW FILENAME
Strings can be compared using the following relational operators:
<>, =, <, >, <=, and >=
Note that these are the same relational operators used with numbers.
String comparisons are made by taking corresponding characters from each
string and comparing their ASCII codes. If the ASCII codes are the same for
all the characters in both strings, the strings are equal. If the ASCII
codes differ, the lower code number precedes the higher. If the end of one
string is reached during string comparison, the shorter string is smaller
if they are equal up to that point. Leading and trailing blanks are
significant. The following are examples of true string expressions:
"AA" < "AB"
"FILENAME" = "FILE"+"NAME"
"X&" > "X#"
"CL " > "CL"
"kg" > "KG"
"SMYTH" < "SMYTHE"
B$ < "9/12/78" 'where B$ = "8/12/85"
String comparisons can be used to test string values or to alphabetize
strings. All string constants used in comparison expressions must be
enclosed in quotation marks. The complete list of ASCII
codes is listed in the ◄ASCII Chart.►