Page 1 of 1

utils.stringFormat() Questions

PostPosted: Fri Dec 07, 2012 2:58 am
by kwpsd
Version: 6.1.3 - build 1424

I am using utils.stringFormat() to create a text-based report and have some questions regarding its capabilities.

Here is the text output that is being generated:

Current Output.png
Current Output.png (17.92 KiB) Viewed 2612 times


Here is the code that generates the output:

Code: Select all
var values = [ line_number, index, description, charge, sales_tax ]

utils.stringFormat( '%1$5.0f %2$7s %3$50s %4$8.2f %5$8.2f', values )


This is the desired output:

Desired Output.png
Desired Output.png (18.06 KiB) Viewed 2612 times


1st Column: What is the specification ('%1$5.0f') to add leading zeros to the 'line_number'?

2nd Column: What is the specification ('%3$50s') to left-justify the 'description''?

Any help is greatly appreciated!

Re: utils.stringFormat() Questions

PostPosted: Fri Dec 07, 2012 8:21 am
by ROCLASI
Hi Kim,

Googling java.string.format padding gave me the answers.
This formatting string gives the output you are seeking:
Code: Select all
utils.stringFormat('%1$05.0f %2$7s %3$-50s %4$8.2f %5$8.2f', values)


Hope this helps.

Re: utils.stringFormat() Questions

PostPosted: Fri Dec 07, 2012 8:13 pm
by kwpsd
Yes, that does help...thank you, Robert!