Search code examples
javajasper-reports

How to use Split in report's expression


Currently attempting to split a large string field into 3 smaller fields. The string delimited by a "/". Example String:

0123/ABCD1234/EFGH909883432212

At the moment I have managed to pull the middle section out using the following expression inside a variable:

$F{String}.split("/" ,5)[1].trim()

To be perfectly honest I am not sure how it works as I do not know what the 5 and 1 are for (which is probably what I need to know to get the other two sections)


Solution

  • After calling method spit an array is created holding substrings which are delimited by "/" in the original string. The trim removes any trailing spaces. Number 5 resembles optional parameter. An integer that specifies the number of splits, items after the split limit will not be included in the array.