text
stringlengths
0
99.6k
$SIZE $LENGTH
These two words are used to determine the length of strings or their maximum allowable size. $SIZE will leave the maximum allowable length of the string on the stack, while $LENGTH will leave the length of the string currently stored in the variable. Example:
NAME$ $SIZE ( leaves the maximum number of characters allowable in NAME$)
NAME$ $LENGTH ( leaves the length of the string currently stored in NAME$)
$!
This word is used to store a string in a variable. You can use it to initialize a string variable from a string literal. Example:
" This is a string" NAME$ $! ( store string literal in NAME$)
Note that strings will be truncated to the max length allowable for the string variable you are moving the string too. So for example, if NAME$ was created with a maximum size of 5, the only characters actually stored in NAME$ would be "THIS ".
You can also move strings from one variable to another with this word:
TRASH$ NAME$ $! ( move the string in TRASH$ to NAME$ )
Note that this word only operates on string variables - you can't use it, for example, to move a string to the PAD (see COPY$ for a way to do this.)
$+
This performs the concatenation operation. Once again, if the total length of the concatenated string exceeds the length of the variable, then the string will be truncated. Example:
FOO$ BAR$ $+ ( the concatenated string is left in FOO$ )
Strings may be added (concatenated) to themselves:
FOO$ FOO$ $+ or FOO$ DUP $+
$?
This simply types out the string. Example:
NAME$ $? ( type current string in NAME$)
COPY$
This word will extract a portion of a string, and move it to another string. It takes four arguments. The string address from which the string is going to be copied, the starting character of the substring, then ending character of the substring, and the destination. Example:
NAME$ 2 4 LIST$ COPY$ ( move characters 2 thru 4 of NAME$ to the start of LIST$)
You can also move a string to the pad with this word:
NAME$ 2 10 PAD COPY$ ( move characters 2-10 of NAME$ to the PAD)
Note that you can move the entire string by simply giving indexes of 1 and 255:
NAME$ 1 255 PAD COPY$ ( move the whole string to the PAD)
+$!
This word is used to store a string in the middle of another string. For example:
NAME$ JUNK$ 4 +$!
Will store NAME$ starting at the 4th character in JUNK$. This is a very useful string operation, particularly in conjuntion with COPY$ :
NAME$ 2 4 PAD COPY$ PAD JUNK$ 4 +$!
Will move the 2 thru the 4th characters of NAME$ to JUNK$, starting at the 4th character of JUNK$ ( try this one in BASIC!).
Note that +$! will only modify an already initialized string. For example, if JUNK$ contains a 10 character string, then:
NAME$ 2 4 PAD COPY$ PAD JUNK$ 11 +$!
will be a null operation. There are often cases when you want to build up an unitialized string from smaller pieces, or to use a single string variable as a one dimensional string array. To do this, you must first initialize the string to all spaces. The word $BLANK has been provided for this purpose. $BLANK will set the entire string to spaces, and then set the length of the string equal to the maximum size for that string. Example:
LIST$ $BLANK ( blank LIST$)
IN$
This word will find the first occurence of a string in another string, and return the index of the first character. If nothing is found, a 0 is returned. Example:
NAME$ LIST$ IN$ ( return the first occurence of NAME$ in LIST$)
$= $< $> $<> $<= $>=
These are the string boolean operators. Note that, everything else being equal, the longer string is considered the greater, and also that lower case is not the same as upper case.
>LOWER
This word is principly useful for carrying out string comparisons when you want to ignore case. It takes a starting address, and a count, and converts the entire thing to lower case. (Lower case being the same as upper case when the computer is in uppercase/graphics mode). Note that the string is converted where it stands, so if you want to preserve the original form, move it somewhere else before using this word.
Example: Check if two strings are equal:
NAME$ TEST$ $=
Example: Check if two strings are equal, but ignore case:
NAME$ DUP COUNT >LOWER TEST$ DUP COUNT >LOWER $=
Example: Check if two strings are equal, ignore case, but preserve the original form of the strings:
NAME$ 1 255 PAD COPY$ ( move to pad)
PAD COUNT >LOWER ( convert to lower case)
TEST$ TRASH$ $! ( move TEST$ to a temporary variable)
TRASH$ COUNT >LOWER ( convert to lower case)
PAD TRASH$ $= ( compare)
INPUT$
This accepts input from the keyboard, and moves the string to the variable whose address is on the stack. Note that the PAD is used for temporary storage, and a copy will remain there immediately after using this word. Note also that the full length of the input will be in pad, but it will be truncated if moved to a variable which is not large enough.