views:

98

answers:

2

I have String tokens separated by $$ which are list of particulars which are further separated by comma (e.g. Peter Adams,255 Jhonson Street, NY,74322 $$ Mary Luther,54 Eglinton Ave.,Mississauga,ON L5A1W6)

I want to display above in following way

Name : Peter Adams
Addr :255 Jhonson Street
City : NY
Pincode :74322

Name : Mary Luther
Addr :54 Eglinton Ave.
City :Mississauga
Pincode :ON L5A1W6

in BIRT output

I have tried using following code

var myexp =/[$$]/;
var match = myexp.exec(dataSetRow["SDR"]);
if(match !=null)
{
array=dataSetRow["SDR"].split("$$");
//dataSetRow["SDR"] ="x";
var string=null;
for(var i=0; i<array.length; i++)
{
string+=array[i]+"\n\n";

}
dataSetRow["SDR"]=string.substring(4,string.length);
}
else
{
dataSetRow["SDR"]=dataSetRow["SDR"];
}

which display string tokens as follows

Peter Adams,255 Jhonson Street, NY,74322 

Mary Luther,54 Eglinton Ave.,Mississauga,ON L5A1W6

Can any one give some suggestion?

A: 

So you've got an "array" populated with tokens. Good! Do another split by a comma (array[index].split(",") ) into another array (say array1) and use individual elements of array1 to output values in the format you want.

DmitryK
A: 

Have you considered using a text control rather than actually over-writing the data binding itself? Inside the text control you can do all your formatting and get the output looking just as you want and still keep the integrity of your data binding intact.

To do this, just drag a text field onto your table (rather than the data element itself). Your text item will have access to each row's data as the table is built out. Then configure the text element for HTML output with a type of "dynamic text" (both are set via drop-downs in the Text Item dialog). Then add this as your expression for generating the text item:

var myexp =/[$$]/; 
var match = myexp.exec(dataSetRow["SDR"]); 
var outString = "";

if(match != null) {
    var splitResult = dataSetRow["SDR"].split(" $$ ");
    for(i = 0; i < splitResult.length; i++){
       outString = outString + splitResult[i].replace(",", ":");  
    } 
}
else
    outString = dataSetRow["SDR"];

"Name:  " + outString;
MystikSpiral