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
|