The STRING command concatenates a list of one or more literal strings, string variables or vector contents into a single string variable. The resultStringVariableName can then be used in any other command (except NEWCMD and INCLUDE) where a string literal is allowed.
If a vector is used as an input argument, it may be accompanied by an optional format specification. The format specification is identical to those used by the WRITE command. For example:
STRING "DataFile_" fileNumber%1F ".txt" fileName
where fileNumber is a vector variable containing one number and the "%1F" is a format specification saying to use fixed point representation one digit wide, minimum. If fileNumber were 3, then fileName would be:
See an example of this usage in a loop at right.
If a vector argument has more than one element, the entire contents of the vector will be converted to a string, as in the following:
COPY 1,5 vec STRING "The vector has these contents: " vec%1.f str PRINT str
Which prints out:
The vector has these contents: (1 2 3 4 5)
You can use the standard escape characters in any literal string argument:
\n newline \r carriage return \t Tab \" literal quote
If the resultStringVariableName is a previously defined string variable, then its old contents are replaced by the new. If the resultStringVariableName is not previously defined, it becomes defined by the STRING command.
If you want to be able to easily distinguish string names from vector names, you could adopt the convention of adding a "$" to the string name either as a prefix or a suffix as in these examples:
STRING "this is a string" sampleString$
STRING "this is a string" $sampleString
A string can be concatenated upon itself like this:
STRING "Marcia " myString STRING myString myString myString myString PRINT myString
Marcia Marcia Marcia
Here's a simple example that creates new names for output data files on each pass through a loop.
STRING "c:/users/john/documents/" filePath FOREACH fileNumber 1,3 'Put code here to generate data for vec1 vec2 vec3 'that differs on each pass through the loop: '. . . 'Write the data out to a different file on each pass: STRING "DataFile_" fileNumber%1F ".txt" fileName STRING filePath fileName fullPathName WRITE FILE fullPathName vec1 vec2 vec3 END
This next example uses STRING to build a complicated HTML prompt string for the INPUT command:
CLEAROUTPUT COPY 0 selection ' to force once through the loop PRINT "\n==================================" INPUT "Enter a vector: " var WHILE selection <> 5 ' loop on computation until user quits
STRING "<html>Current vector: " var "<hr>1. Enter new vector.<br>2. Compute mean.<br>3. Compute standard deviation.<br>4. Compute range.<br>5. Quit.<br>Enter selection: " promptString
INPUT promptString selection IF selection = 1 PRINT "\n==================================" INPUT "Enter a vector: " var ELSEIF selection = 2 MEAN var result OUTPUT " The mean is: %12.4G\n" result ELSEIF selection = 3 STDEV var result OUTPUT " The standard deviation is: %12.4G\n" result ELSEIF selection = 4 MIN var varMin MAX var varMax OUTPUT " The range is: %12.4G to %12.4G\n" varMin varMax ELSEIF selection = 5 PRINT "Quitting." COPY 0 keepGoing ELSE PRINT "ERROR: selection must be between 1 and 5" END END