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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing text into discreet elements in Crystal 9.0 1

Status
Not open for further replies.

Goosetown

Technical User
May 26, 2004
8
0
0
CA
I need to write a Crystal formula that parses out the text from a field into discreet elements and I'm at my wits end. Basically the output from this field looks like:

[G]Good <F>Fair <P>Poor or
<1>`1T3 <4>`4T6 <7>`7T10 or
[N]None Seen <P>Eos Present

I need a formula that will strip out the "[]" and the "<>" parse out this field into something like:
Good
Fair
Poor or
1T3
4T6
7T10 or
None Seen
Eos Present

The number of elements can vary from 2 or 3 up to 10 or 11 and the delimeters can change from [] to <> to ().

Thanks for any help at all.
 
Use a formula that first replaces the delimiters with a standard delimiter. In each replace step, the resulting string should be loaded into a string variable.

Then, the formula should use the Split() function to turn the string into an array.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Use this formula, replace the item in bold with your real field :

Local StringVar String := {MyTable.MyField};
Local StringVar Result := "";
Local NumberVar Counter = 0;

If Instr(String,"[") <> 0 or Instr(String,"]") <> 0 then
(While Instr(String,"]") <> 0 Do
(String := If Instr(String,"[") = 1 then Mid(String,4) else
Left(String,Instr(String,"]")-2)&Mid(String,Instr(String,"]")+1);););

If Instr(String,"<") <> 0 or Instr(String,">") <> 0 then
(While Instr(String,">") <> 0 Do
(String := If Instr(String,"<") = 1 then Mid(String,4) else
Left(String,Instr(String,">")-2)&Mid(String,Instr(String,">")+1);););

If Instr(String,"(") <> 0 or Instr(String,")") <> 0 then
(While Instr(String,")") <> 0 Do
(String := If Instr(String,"(") = 1 then Mid(String,4) else
Left(String,Instr(String,")")-2)&Mid(String,Instr(String,")")+1);););

String := Replace(String,"`","");
String := Replace(String,"[",Chr(13));
String := Replace(String,"<",Chr(13));
String := Replace(String,"(",Chr(13));

String;

Hope this helps....

Reebo
 
Or you could also use :

Local StringVar String := {MyTable.MyField};
Local StringVar Result := "";
Local NumberVar Counter = 0;

String := Replace(String,"`","");


While Counter <> Len(String) Do
(
Counter := Counter +1;
If Mid(String,Counter,1) in ["[","<","("] then
(Counter := Counter + 2;
Result := Result & Chr(13);) Else
Result := Result & Mid(String,Counter,1););

If Left(Result,1) = Chr(13) then Mid(Result,2) Else Result;


PS. Remeber to set your formula field to Can Grow (Right Click, Format Field, Common, Can Grow)

Reebo
 
Thank you Reebo99. That was brilliant. Both formulas worked like a charm.

Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top