Formatting text field possibly using regex

0

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
 

 

JR_Data's picture
Joined: Jul 15 2017 - 7:02am
Last seen: 1 week 5 hours ago

1 Answer:

0

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

 

darth_fader's picture
Joined: Mar 7 2010 - 9:45pm
Last seen: 2 days 18 hours ago
Feedback
randomness