X
19064

How do I use C printf-style quoted string format codes and escape sequences?


C printf-style quoted string format codes and escape sequences will work only when placed inside of a quoted string format description that is preceded with a percent (%) character. 
For example, to format strings and also to embed a tab character using the C printf-style "\t" escape sequence within a printed line (in this case between the strings 'like' and 'IDL'), one might issue the following IDL PRINT command with FORMAT specification:

IDL> PRINT,'I','like','Interactive','Data','Language', $
   FORMAT='(%"%s %s\t%1s",a1,a1)'

Which results in the following output:

    I like   IDL

Notice that the "%" character is immediately before the double-quoted format string, and that "%s" prints the arguments 'I' and 'like' as full strings. Backslash-t (\t) specifies a tab character. The code "%1s" indicates that the string argument "Interactive" should print with only one character for its width (resulting in the letter "I").

Also notice that you can mix in Fortran style of formatting with C printf-style formatting. In this example the code "a1" specifies the format for printing the last 2 string arguments, 'Data' and 'Language', each also with a single character width. This results in the output of "D" and "L".

Tip: To display a double-quote character use \" and to display a single-quote (apostrophe) use '' (two single quotes) inside your formatting string. The following example shows how to display single-quote and double-quote characters:

IDL> PRINT, !dpi, $
   FORMAT='(%"IDL''s version of \"pi\" is %14.11f, approximately.")'

IDL's version of "pi" is 3.14159265359, approximately.



Additional details about supported format codes and character escape sequences in IDL can be found in the "Format Codes" section of the "Programming in IDL" document or in the IDL Online Help
.