Search code examples
jasper-reports

JasperReports: spliting string value with delimiter


I have a problem with JasperReports. I am passing string values to a report. A specific code has included to each and every value that I’m passing, like “pre: 001”, “ab: 002”, “lv: 003”.

Codes - “pre”,”ab”,”lv”

As I mentioned above, each code and value can separately identify by “:” notation. In Java I used following code to separate the code and value;

a = “pre:001”;
String[] b = a.Split(“:”,2);
System.out.println(b[0]);  // code
System.out.println(b[1]);  // value

Problem

I need to pass combined value (code+value) to the report but the text field should only appear the value portion.

Ex:

Input – “pre:010”

Output-“010”


Solution

  • That should be in the text field expression for field A:

    $F{A}.split(":",2)[1].trim()