Link to home
Start Free TrialLog in
Avatar of kelsanit
kelsanit

asked on

Crystal - Return values in string seperated by & sign into seperate fields

I have a crystal report with a string that is seperated by & signs. I am wanting to seperate the string into diffrent fields so i can use in other functions.

Example:
String:  06/01-120&06/01-228&06/02-300&6/5-300

Expected output:
Value1 = 06/01-120
Value2 = 06/01-228
Value3 = 06/02-300
Value4 = 06/05-300
Avatar of Mike McCracken
Mike McCracken

You can split the field into an array of strings with the SPLIT function

Split({YourField},'&')

You can then display them individually with Split({YourField},'&')[1]

To preserve the values for use in other formulas create a formula
WhilePrintingRecords;
Global StringVar Array arrDates;
arrDates := Split({YourField},'&');
''

Open in new window


In another formula you can display the values
WhilePrintingRecords;
Global StringVar Array arrDates;
arrDates[1]

Open in new window


mlmcc
If the number of values in the field can vary, you can use UBound to test how many values there are, to avoid getting a subscript error.  For example, if the field contained "06/01-120&06/01-228", that would give you an array with 2 elements, so Split ({field}, "&") [ 3 ] would give you an error.  You can avoid that by using something like this:

if UBound (Split ({field}, "&")) >= 3 then
  Split ({field}, "&") [ 3 ]


 James
Avatar of kelsanit

ASKER

There could be only one value in the field or 3 or 4.  I tried adding the UBound to the first part of the formula but returned 0 results. When i use the original formula provided it just give me error "A subscript must be between 1 and the size of the array"
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked perfect!

Thank you.