Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: between / and / Post Reply Post New Topic
Author Message
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Topic: between / and /
    Posted: 07 Dec 2012 at 1:04am
Hi all,

I have a question. I have a field which contains the following information

EUR(5) / EUR BN : *********(SM) / FRM PAY FILE WK 48 / ******** /

Now I need to split up this information into different fields. I need the information between the second and the third /, and I need the information between the third and fourth /. I don't know exactly how to do this.

Can anyone help me with this? Any help would be highly appreciated

Kind regards

Gerben
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Dec 2012 at 4:17am
This is not too difficult.  It will look something like this to get the text between the second and third /:
 
NumberVar slashAt;
StringVar result := {MyTable.MyField};
 
//find the first slash
slashAt := InStr(result, "/");
//get the second slash
slashAt := InStr(slashAt + 1, result, "/");
//get the first part of the substring
result := mid(result, slashAt + 1);
//find the third slash
slashAt := InStr(result, "/");
//get the final result
result := left(result, slashAt - 1);
result
 
You should be able to figure out how to get the other part from here - it will need to be in a separate formula from this one.
 
-Dell
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 07 Dec 2012 at 7:38am
Thank you for you help, this formula works. But I can't seem to get the other formula working. No matter how I alter it, it keeps giving me the same result as the current formula
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Dec 2012 at 8:35am
After you get the location of the second slash, you need to get the location of the third slash.  From there, the rest of the formula is the same.  So, it will look something like this (added code in italics):
 
NumberVar slashAt;
StringVar result := {MyTable.MyField};
//find the first slash
slashAt := InStr(result, "/");
//get the second slash
slashAt := InStr(slashAt + 1, result, "/");
//get the third slash
slashAt := InStr(slashAt + 1, result, "/");
//get the first part of the substring
result := mid(result, slashAt + 1);
//find the fourth slash
slashAt := InStr(result, "/");
//get the final result
result := left(result, slashAt - 1);
result
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 08 Dec 2012 at 4:00am
When I put this in my second formula, I get an error in the first formula saying

"String length is less than 0 or not an integer"

It highlights the line

//get the final result
result := left(result, slashAt - 1);
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Dec 2012 at 3:08am

So, you need to check to see whether slashAt is > 0.  If it is, use Left() on the result.  If it isn't, just use the result as is.

 
-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.032 seconds.