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

Dynamic String Parsing

Status
Not open for further replies.

jlopeman

IS-IT--Management
Apr 25, 2011
35
Good morning,

Using Crystal XI and MS SQL 2008R2 database, I'm trying to parse a string that's basically a condition stored in the database. Here's and example of the format of the string:

{dbTable.dbField}="some medication name" & {dbTable.dbField}="some medication strength" & {dbTable.dbField ="some boolean condition"

I've created a formula to parse out the medication name, which is what I want the results to be:

WhilePrintingRecords;
Mid({string}, InStr({string},'"'), Instr({string},'"'))

This kind of works for the first medication listed, but the formula seems to be cutting off the med. names that are longer, or returning too much of the string.

I need to capture whatever is inside of the first set of quotes, regardless of the length of that substring. Then, I'll need to go back and capture whatever is in the second set of quotes for another formula to capture the Rx strength.

Thanks in advance,

Jason

 
I solved my question using T-SQL and a command. But, if possible, I'd like to know how to do this using a crystal formula.
 
Try something like this:

//{@first set of quotes}:
stringvar x := {table.memo];
stringvar array y := split(x,"&");
extractstring(y[1],",")

//{@second set of quotes}:
stringvar x := {table.memo];
stringvar array y := split(x,"&");
if ubound(y)>=2 then
extractstring(y[2],",")

//{@third set of quotes}:
stringvar x := {table.memo];
stringvar array y := split(x,"&");
if ubound(y)>=3 then
extractstring(y[3],",")

//etc.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top