jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Lambrechtsen <>
Subject Zero Padding in JMeter using Beanshell
Date Thu, 28 Mar 2013 20:24:10 GMT
I recently had a need to create a zero padded value in JMeter and thought I
would share the Beanshell code I used to get it working.

I wasn't sure why I needed to put the long into a Java Array to make it
work with String.format but this worked for me using a Beanshell Sampler
taking a counter:

String inputcounter = vars.get("InputCounter");
Long[] longarray = new Long[] {Long.valueOf(inputcounter)};
String paddednumber = String.format("%019d", longarray);

This will create a padded number up to 19 digits "%019d" change the 19 to
the number of padded digits you need.

This way I could have a JMeter counter with the reference / variable name
"InputCounter" inside a loop, use that value and also create a padded
version of the number as "PaddedCounter".

I am sure there are cleaner ways of doing it but this worked for me :)



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message