1. Create a new report called String Length.rptdesign.
2. Drop a Data element anywhere on the Report Design.
3. Use the following Expression:
"This is a test".length
4. Hit OK, and Preview the report.
A simple report with the number 14 should be displayed. The above Expression can
also be replaced with the following Expression:
var testString = "This is a test";
testString.length;
Chapter 10
[ 241 ]
In the above example, we are breaking from the one line Expression and using
multiple lines and a variable. The key is that the last line is returning a single value.
All sorts of computations can take place, as long as a single value is returned. If we
change the Expression to the following:
var testString = "This is a test";
var splitString = testString.split(" ", 5);
splitString[3].toUpperCase();
the report will only return the word TEST. Again, while multiple things are being
done in this Expression, such as the assignment of the String, splitting the String, and
converting the 3 element to upper case, only a single result is returned.
Calling Java Objects in Expressions
In the Bar Chart example from the last chapter, we used another method to retrieve a
formatted date. Let's look at the following code sample:
importPackage(java.text);
var dateFormater = new SimpleDateFormat("yyyy-MM");
dateFormater.
Pages:
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192