Monday, February 2, 2009

To split a string in Crystal report formulae editor

          This is a code to split a long string in the database to be used in crystal reports, for eg. an address field with each particular sectors in address separated by a delimiter like a comma.First of all you have to create a new formula field like @address and edit the formula with the formula editor which is provided inside the crystal reports.Below is the input database string to be split
Address field stored in the database:
House No-999,Sector-343,Mayhelm Street,PostOffice,657466
The code to be written inside the formulae editor for @address formulae field to display the address after splitting is given below
stringVar array x := split({Tablename.Addressfield},",");
Local numberVar i;
Local stringVar outputString := "";
For i:=1 to Count(x) do
(
outputString := outputString + x[i] + Chr(10)
);
outputString;
The outputString is the result which is the wanted address in the format given below
House No-999,
Sector-343,
Mayhelm Street,
PostOffice,
657466
Explanation of the code:
          The address field from the database is first of all split using the function Split(field,delimiter) in the formula editor.This is stored in an array and then iterated and concatenated one by one to the outputString.The Chr(10) used is to jump to new line after printing each strings seperated after comma.

7 comments:

Aparna Randive said...

Thank you very much...it saved my time a lot

Unknown said...

If I use this formule for my string which is seperated by a semicolon, the outcome will look like this:

text1
text2
text3
text4

I like to have the outcome started at some point for each line
How to?

Unknown said...

I see the outcome in my comment is not correct, he striped out the spaces

text1
 text2
 text3
 text4

Unknown said...

Thank You Very Much...

Unknown said...

Greate Brother i like so much and lot of thanks................

Unknown said...

A lot of thanks brother............

Unknown said...

NICE 高大上