- Form: STRING name ['format string'] [expressions]
-
- Form: STRING name '?query'
STRING defines string variables. String variables are names to which a
character string is associated.
STRING works like PRINTF (see that section of the help information), except
that the name of the string variable being defined appears between the
command STRING and the format string. As in PRINTF, you can define strings
directly, as in:
- STRING EXPR 'This is a string with seven words.'
-
- STRING HELLO 'Hello, world'
Remember that multiple words to be considered as one string must be
enclosed in quotes. If you wish to define a blank string, you must define
it as a single blank in quotes, as in:
You may also define strings using expression evaluation as in:
- J=7
- STRING NAME 'FILE%I3.3' J
which evaluates the numeric variable J, then substitutes its value into the
string beginning FILE..., and loads the final string into the stack of
string variables under the name J. In this example, the value of the
string variable NAME is FILE007.
If the first character of the format string is a question mark, STRING will
print the remainder of the format string as a prompt, then pause while you
enter the string. This allows the interactive definition of strings. If
the format string contains only a question mark, then the prompt will be
'Enter' followed by the name of the string variable which is being defined.
Examples:
- STRING FILE '?Enter a filename for this image. >> '
- will
print 'Enter a filename for this image. >> ' then pause while you
enter a name. Your reply will be loaded into the character string
FILE.
- STRING HEADER ?
- will print 'Enter HEADER ' then accept a
string.
You CANNOT evaluate arithmetic expressions when defining strings
interactively. Thus
- STRING FILE '?Enter a file for image %I2 ' J
will NOT work. The newline character (\n
) will also not work.
You can list all defined strings with the command PRINT STRINGS.
A string variable can be substituted into a command line by enclosing the
name of the string in braces. See HELP SUBSTITUTE for more information,
plus information about printing STRINGS.
String variables are stored in a different stack from numeric variables.
Thus it is possible to have a string variable and a numeric variable with
the same name.