X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 14 Apr 2008 01:20 PM by  anon
Character Escapes in IDL for strings (carriage returns, etc)
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
14 Apr 2008 01:20 PM
    Hello, Is there a way to force a carriage return in the middle of a string in IDL? For example, in C or C++ one can put a "/n" for a new line in the middle of a print statement. Is this possible in IDL? Thanks,

    Deleted User



    New Member


    Posts:
    New Member


    --
    14 Apr 2008 01:20 PM
    In IDL the '\n' character of the C programming language must be input by its ASCII numeric byte value, or, in the case of Windows, values. In Windows a newline is represented by two characters, 13B followed by 10B. On UNIX it is represented by one character, 10B. The cross-platform syntax for the newline would then appear like this: if (!D.NAME eq 'WIN') then newline = string([13B, 10B]) else newline = string(10B) myTwoLineString = 'First Line' + newline + 'Second Line' ; Example of use print, myTwoLineString There is only one problem with this. Although this works for outputting text with PRINT and PRINTF, it does not work with, for example, XYOUTS (outputting text to a Direct Graphics window), and it is rarely, if ever, the ***best*** way to generate a newline. Thus, even in PRINT and PRINTF and most definitely in strings that are to be used in IDL Widgets, the preferred way to have a two-line string is to store the string as a two-element string array, e.g.: myTwoLineString = ['First Line', 'Second Line'] print, myTwoLineString, FORMAT='(A)' ; ... or ... widget_control, wText, SET_VALUE=myTwoLineString In IDL Direct Graphics the method for newlines is to use an "embedded formatting command" as it is called in Online Help. So this is how the code might look: newline = '!C' ; myTwoLineString = 'First Line' + newline + 'Second Line' ; Example of use xyouts, 0.5, 0.5, myTwoLineString, ALIGNMENT=0.5 James Jones
    You are not authorized to post a reply.