Formatting string data
Typically, you format string data to fix inconsistent or poorly formatted data that is retrieved from the data source. The data source, for example, can store names with inconsistent capitalization or phone numbers in 1234567890 format. To fix these problems, specify the desired string format.
Display string data using either a text element or a data element, depending on what you want to accomplish. When you drag a data set field from Data Explorer and drop it on the report page in the layout editor, BIRT Report Designer creates a data element to display the values of the data set field. The procedure for formatting data differs for a data element and a text element, and is described in the following sections.
Formatting text in a data element
Specify a text format by setting the data element’s Format String property, as shown in Figure 8‑5.
Figure 8‑5 Format String property values
Table 8‑4 describes the available string formats.
Table 8‑4 Examples of string formats
Format type
Description
Example of data appearance
Lowercase
Converts the string to lowercase
smith
Uppercase
Converts the string to uppercase
SMITH
You can also define custom string formats using special symbols. Table 8‑5 describes these symbols.
Table 8‑5 Symbols for defining custom string formats
Symbol
Description
>
Converts string characters to uppercase.
<
Converts string characters to lowercase.
@
Character placeholder. Each @ character displays a character in the string. If the string has fewer characters than the number of @ symbols in the format pattern, spaces appear. Placeholders are filled from right to left, unless you specify an exclamation point (!) at the beginning of the format pattern. See Table 8‑6 for examples.
&
Same as @, except that if the string has fewer characters, spaces do not appear. See Table 8‑6 for examples.
!
Specifies that placeholders are to be filled from left to right. See Table 8‑6 for examples.
Table 8‑6 shows examples of custom format patterns and their effects on text data.
Table 8‑6 Results of custom string format patterns
Format pattern
Data in data source
Result
(@@@) @@@-@@@@
6175551007
5551007
(617) 555-1007
(   ) 555-1007
(&&&) &&&-&&&&
6175551007
5551007
(617) 555-1007
() 555-1007
!(@@@) @@@-@@@@
6175551007
5551007
(617) 555-1007
(555) 100-7
!(&&&) &&&-&&&&
6175551007
5551007
(617) 555-1007
(555) 100-7
!(@@@) @@@-@@@@ + ext 9
5551007
(555) 100-7    + ext 9
!(&&&) &&&-&&&& + ext 9
5551007
(555) 100-7 + ext 9
>&&&-&&&&&-&&
D1234567xy
D12-34567-XY
<&&&-&&&&&-&&
D1234567xy
d12-34567-xy
Formatting text data in a text element
To insert dynamic data in a text element, use the VALUE-OF tag. To format the dynamic data, include a format attribute that specifies the format, as shown in the following examples:
<VALUE-OF format="(@@@) @@@-@@@@">row["phone"]</VALUE-OF>
<VALUE-OF format=">">row["custName"]</VALUE-OF>
You can use any format pattern that the Format String property supports, as described in the preceding section.