Reference Guide > S Routines > STRING Function
  

STRING Function
Converts the input parameters to characters and returns a string expression.
Usage
result = STRING(expr1, ... , exprn)
Input Parameters
expri—The expressions to be converted to type string.
Returned Value
result—The string value for expr.
Keywords
Format—Allows the format of the output to be specified in precise detail, using a FORTRAN-style specification. FORTRAN-style formats are described in the PV‑WAVE Programmer’s Guide.
Print—If present and nonzero, specifies that any special case processing should be ignored, and that STRING should behave exactly as the PRINT procedure.
Discussion
STRING can be used to convert one or more expressions to string data type. You can use the Format keyword to explicitly specify the format in the converted string. The format specification string used with the Format keyword follows this syntax:
"(q1f1s1f2s2...fnqn)" 
where:
*q—is an optional slash (/) record terminator. During output, each record terminator causes the output to move to a new line. During input, each record terminator causes the next line of input to be read.
*f—is a FORTRAN-style format string. Some format strings specify how data should be transferred while others control some other function related to how I/O is handled. If you do not specify a format string, the result is formatted automatically.
*For more information about the FORTRAN format codes that can be used, refer to the PV‑WAVE Programmer’s Guide.
*s—is a comma (,) or a slash (/) that is used to separate input values. The only restriction on these separators is that two commas cannot occur side by side.
 
note
The quotation marks and parentheses surrounding the format string are required. The quotation marks can be either single or double quotation marks.
If the Format keyword is not present, PV‑WAVE uses its default rules for formatting the output. These rules are described in the section Free Format Output in Chapter 8 of the PV-WAVE Programmer’s Guide.
STRING is similar to the PRINT procedure, except that its output is placed in a string rather than being output to the terminal.
Example 1
The following three commands all yield the string scalar 'ABC':
x = STRING([65B, 66B, 67B])
y = STRING([BYTE('A'), BYTE('B'), BYTE('C')])
z = STRING('A' + 'B' + 'C')
PRINT, x, '   ', y, '   ', z
In the first expression, the input x is a byte vector, and STRING converts it into a string scalar. The first parameter is 65B, which is a notation indicating that the parameter uses a byte data type, but the result is equal to the decimal ASCII code 65.
Example 2
STRING can also be used with a floating-point variable.
x = 123.45
result = STRING(x)
PRINT, result
; PV-WAVE prints: 123.450
Example 3
Here are some examples using the Format keyword. In these examples, the Format keyword instructs the STRING function to convert numbers to a string data type, using an integer format with a maximum field width of 2 characters. In all three cases, the STRING command entered is:
result = STRING(numbers, Format='(I2)')
*Case 1: When numbers = [36, 9, 72], and result is computed with the format string shown, the result is:
PRINT, result
; PV-WAVE prints: 36  9 72
The values are converted to strings, using a maximum field width of two characters.
*Case 2: When numbers = [5, 7, 9, 100], and result is computed with the format string, the result is:
PRINT, result
; PV-WAVE prints: 5  7  9 **
The two asterisks indicate that the integer value 100 was too big to be read with an I2 FORTRAN format.
*Case 3: When numbers = [6.12, 4.507, 4.339], and result is computed with the format string, the result is:
PRINT, result
; PV-WAVE prints: 6  4  4
As this example shows, an integer format can be used to output floating point data, but all digits after the decimal point are lost.
See Also
PRINT, STRARR, XYOUTS
For more information on string formats and format specification codes, see the PV‑WAVE Programmer’s Guide.

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.