utils.stringFormat() Questions

Questions, tips and tricks and techniques for scripting in Servoy

utils.stringFormat() Questions

Postby kwpsd » Fri Dec 07, 2012 2:58 am

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 2589 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 2589 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!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Re: utils.stringFormat() Questions

Postby ROCLASI » Fri Dec 07, 2012 8:21 am

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: utils.stringFormat() Questions

Postby kwpsd » Fri Dec 07, 2012 8:13 pm

Yes, that does help...thank you, Robert!
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA


Return to Methods

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron