Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting a String Into Diff Fields

Status
Not open for further replies.

aj3221

Technical User
May 14, 2008
79
US
I have a field that I would like to split.

Right now it looks like:
cono=1 orderno=1255193 ordersuf=00 lineno=5

I would like to split those into 4 separate fields. I just need to see the data:

1
1255193
00
5

The words and = are always the same: cono=, orderno=, ordersuf= & lineno=

Can you help? Thanks so much in advance!
 
i do not have crystal in front of me so i apologize in advance for any mistakes, but i think you should be able to create 4 formulas similar to below to get what you need.

{@Value1}
numbervar ono := instr({table.field},'orderno=');
MID({table.field},5,ono-1);

{@Value2}
numbervar ono := instr({table.field},'orderno=');
numbervar ors := instr((table.field},'ordersuf=');
MID({table.field},ono+7,ors-1);

{@Value3}
numbervar ono := instr({table.field},'orderno=');
numbervar lno := instr({table.field},'lineno=');
MID({table.field},ors+8,lno-1);

{@Value4}
numbervar ono := instr({table.field},'orderno=');
MID({table.field},lno+6);


 
Hi there! Thank you for replying. Here are the results I'm getting for each formula above:

value1
=1 orde

value 2
=1255193 ordersuf=00 li

value 3
1255193 ordersuf=00 lineno=5

value 4
o=1255193 ordersuf=00 lineno=5
 
using fisheromacse idea, try:

{@Value1}
numbervar ono := instr({table.field},'orderno=');
numbervar ors := instr((table.field},'ordersuf=');
MID({table.field},6,ors-ono-14);

{@Value2}
numbervar ono := instr({table.field},'orderno=');
numbervar ors := instr((table.field},'ordersuf=');
MID({table.field},ono+8,ors-ono-9);

{@Value3}
numbervar ors := instr({table.field},'ordersuf=');
numbervar lno := instr({table.field},'lineno=');
MID({table.field},ors+9,lno-ors-10);

{@Value4}
numbervar lno := instr({table.field},'lineno=');
MID({table.field},lno+7);
 
Or a slightly simpler alternative would be:

{@Value1}
Val(Split({Table.Field},'=')[2])

{@Value2}
Val(Split({Table.Field},'=')[3])

{@Value3}
Val(Split({Table.Field},'=')[4])

{@Value4}
Val(Split({Table.Field},'=')[5])

The results returned are numeric rather than text so format the result to remove decimals etc, or convert it to text in the formulas themselves using "ToText".


Cheers
Pete
 
Assuming no spaces inside field names, here is a simpler approach:

Split({Table.Field}, " ")
gives you an array of name=value pairs

Then, to grab any value, simply split the array element with "=" and get the 2nd element.

hth,
- Ido

view, export, burst, email, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top