Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: truncate with a variable field length Post Reply Post New Topic
Author Message
dhazen
Newbie
Newbie


Joined: 11 May 2010
Online Status: Offline
Posts: 7
Quote dhazen Replybullet Topic: truncate with a variable field length
     Posted: 11 May 2010 at 5:53am
I have a field that contains data that looks similar to the following:
TIRD-64-1.125-US
TIPL-2-2-US
 
I need to capture only the data up to the second hyphen.  I cannot use the left or mid as the field length varies.  Any suggestions?
I am trying to retrieve only the TIRD-64 and the TIPL-2.

Thank you!
Deb
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 May 2010 at 6:41am
Maybe:
 
left({field},
instr(
(instr(
{field},'-')+1),
{field},'-')-1
)
IP IP Logged
dhazen
Newbie
Newbie


Joined: 11 May 2010
Online Status: Offline
Posts: 7
Quote dhazen Replybullet Posted: 11 May 2010 at 9:14am
That worked great!
Thank you!
Deb
IP IP Logged
dhazen
Newbie
Newbie


Joined: 11 May 2010
Online Status: Offline
Posts: 7
Quote dhazen Replybullet Posted: 19 May 2010 at 11:12am
Here's another one...
TIRD-64-.071-US and
TIRD-2-1.4375-STA-US
 
I'm trying to capture only the .071 and the 1.4375

Any suggestions on how to capture the data AFTER the second hyphen?
Thank you!
 
Deb
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 May 2010 at 11:24am
I am sure there is a more elegent loop process but i think this will work:
 
mid({field},
instr(
(instr({field},'-')+1),
{field},'-')+1,
instr(
instr(
(instr({field},'-')+1),
{field},'-')+1,{field},'-')-
(instr(
(instr({field},'-')+1),
{field},'-')+1)
)
IP IP Logged
dhazen
Newbie
Newbie


Joined: 11 May 2010
Online Status: Offline
Posts: 7
Quote dhazen Replybullet Posted: 20 May 2010 at 4:38am
This works!
 
Thanks again Master!
Deb
IP IP Logged
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