INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

String Parsing Assistance Request

String Parsing Assistance Request

(OP)
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

RE: String Parsing Assistance Request

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

RE: String Parsing Assistance Request

(OP)
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

RE: String Parsing Assistance Request

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

RE: String Parsing Assistance Request

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

RE: String Parsing Assistance Request

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close