X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



19069 Rate this article:
3.6

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
.

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »