Re: String Formatting [message #64821] |
Mon, 26 January 2009 11:32  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Mon, 26 Jan 2009, David Fanning wrote:
> Folks,
>
> Before I re-invent the wheel, I thought I would ask.
>
> I wish to write an ASCII text file with two columns of
> text. The first column should be 30 characters wide,
> the second column should be 45 characters wide.
>
> BUT, I wish the data in the columns to be *left*
> justified, not right justified.
>
> What trick to you use, or what formatting string will
> give me this kind of output?
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
Hi David,
try '-' in the format:
Syntax of Format Codes
The syntax of an IDL format code is:
[n]FC[+][-][width]
- is an optional flag that specifies that string or numeric values should
be output with the text left-justified. Normally, output is right-justified.
regards,
lajos
|
|
|
Re: String Formatting [message #64822 is a reply to message #64821] |
Mon, 26 January 2009 11:29   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> Before I re-invent the wheel, I thought I would ask.
>
> I wish to write an ASCII text file with two columns of
> text. The first column should be 30 characters wide,
> the second column should be 45 characters wide.
>
> BUT, I wish the data in the columns to be *left*
> justified, not right justified.
>
> What trick to you use, or what formatting string will
> give me this kind of output?
Never mind, you guys are too slow. I wrote my own. :-)
FUNCTION LeftJustify, theString, theWidth
IF N_Elements(theString) EQ 0 THEN RETURN, ""
IF N_Elements(theWidth) EQ 0 THEN theWidth = 50
justifiedString = String(BytArr(theWidth) + 32B)
StrPut, justifiedString, theString
RETURN, justifiedString
END
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: String Formatting [message #64920 is a reply to message #64821] |
Mon, 26 January 2009 11:54  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Lajos writes:
> try '-' in the format:
Ah, I had a feeling that was there somewhere! Thanks. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|