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!

String Parsing Assistance Request

Status
Not open for further replies.

0sprey

Technical User
May 9, 2015
81
CA
I am working on a formula to modify the following string condition:

DM=xxxxxxx,PV=abc,PV=def,PV=hij,PV=klm,PV=nop,ED=qrs,ED=tuv,ED=wxy

- The lower case characters represent the data
- Within each set of data the number of characters can vary
- The following characters are static within the string : “DM=” “,PV=” “,ED=”

I am trying to achieve the following string condition:

abc – def – hij – klm – nop – qrs – tuv - wxy


By way of one only formula that produces the resulting string
OR
As a set of several formulas each producing one of the eight portions of the string

I have tried several formulas with combinations of ‘REPLACE’ ‘SPLIT’ and ‘MID’ functions but I am not quite there yet.
Any advice on what functions or combinations of functions would be the best choices here would be very helpful.

Thank you, KMD
 
As is usually the case with Crystal Reports there is more than 1 way to do this. The following solution works for the sample data you provided but will need to be tested against all data to determine if it is going to be any use.

Code:
WhilePrintingRecords;
Local NumberVar c;
Local NumberVar i;
Local StringVar R;

c := UBound(SPLIT({Table.Field}, '='));

For i := 3 to c do
R := R + SPLIT({Table.Field}, '=')[i];

REPLACE(REPLACE(R, ',PV',  ' - '), ',ED', ' - ')

Hopefully it will get you to where you need to be, but post back if you need assistance.


Cheers
Pete
 
Thank you Pete,

The string looks as follows after the formula runs :

abc,PVdef,PVhij,PVklm,PVnop,EDqrs,EDtuv,EDwxy

The “DM=xxxxxxx,PV=” portion was removed from the front end of string exactly as required.


However,
The “,PV=” needed to be replaced by “ – “ It has been replaced with “,PV” (The “=” only has been removed.)
This is the same condition for “,ED=”.

I was going to try a few modification however I thought I would post first as this formula has me punching above my weight class.
Thanks, KMD
 
I tested this by copying the string you provided, and developed the code to give you what I think you want.

The resultant output from my formula (copied and pasted from my report) is: "abc - def - hij - klm - nop - qrs - tuv - wxy"

If you are getting a different result it seems to me that either the data is not quite like you described in your original post, or you did not implement my solution exactly. To do so, copy my code into a formula, and change {Table.Field} to reflect the correct field name.

If that's what you did, I'm not sure what else to say.

Regards
Pete
 
It looks to me like you omitted the last line of my formula.

Alternatively, are you certain the actual data does not contain spaces (or other characters) you might have missed from your post?

Cheers
Pete
 
Pete,
You are exactly right. For confidential reasons I had to change the string I posted initially before for posting on line.
When copying and paste the actual characters in to your formula there was a typo. That typo is corrected and your code works perfectly.

And my word… this is nice solution. Thank you very much ! KMD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top