Jump to content
Changes to the Jaspersoft community edition download ×

Formatting text field possibly using regex


JR_Data

Recommended Posts

A single field (description)  in the database is being returned as a large string

-audi-00234-nottingham-red-
 So subsequent fields would look like
-vauxhall-00184-leeds-silver-
-rover-00034-london-black-
 
How do I render each field $F{description} so it is readable so to access city field to return nottingham, leeds london etc. Or to access car $F{description} field. Have found some examples on the formatting using regex but nothing is particularly clear. Is there any formatting option in JasperStudio I am missing
 

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You may or may not be able to pull this off by nesting a bunch of the "TEXT" functions built in to jaspersoft studio, combining 'substitute',and 'search' to whittle this string down to everything between the third and fourth instances of '-', but I don't recommend it. If it is possible, it's not easily maintainable. What you could do is add apache's commons-lang jar into your project, split that string (using, no surprise, the StringUtils.split() method) on the '-' hyphen char, and return the appropriate string from the resulting array list. The split method can split your string into an array list of strings based on a given character. 

 

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#split-java.lang.String-char-

Also, to be fair, Java also has a string split method, but it's not as intuitive:

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String,%20int)

And finally, I'm sure you can do this via regex as well, but again it's not as intuitive as the apache commons-lang approach:

https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...