I am using iReport for designing of reports. I need to format a string such as xxxxxxxxxxx
to xxx xxx xxx xxx
. I am able to specify pattern for date, number, time and currency.
But how do I do this for a string? Can anyone provide me an insight on this.
I solved this by using scriptlet. Thanks for the reply will try your method also.
public String formatNum(String tabn) {
String num = tnum;
String temp, t1, t2, t3, t4;
temp = org.apache.commons.lang.StringUtils.leftPad(num, 11, '0');
t1 = temp.substring(0, 2);
t2 = temp.substring(2, 5);
t3 = temp.substring(5, 8);
t4 = temp.substring(8, 11);
num = t1 + " " + t2 + " " + t3 + " " + t4;
return num;
}
And write this method in a class which extends JRDefaultScriptlet class and export it as jar and then add this to your iReport's Classpath. Now add it as scriptlet and then you can use this method to format to the above required format in your report.