Tips and Tricks
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Tips and Tricks
Message Icon Topic: Removing data at the right of a string Post Reply Post New Topic
Author Message
Naithan
Newbie
Newbie
Avatar

Joined: 12 Mar 2012
Online Status: Offline
Posts: 4
Quote Naithan Replybullet Topic: Removing data at the right of a string
    Posted: 12 Mar 2012 at 10:29pm
I want to remove the last 3 characters of a string which could be any length and either alpha or numeric.
 
E.G.
nhttest001 needs to be nhttest
123456010 needs to be 123456
 
Anyone got any ideas how to do this ?
 
Thanks
Naithan
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Mar 2012 at 3:41am
left(field,len(field)-3)
IP IP Logged
Naithan
Newbie
Newbie
Avatar

Joined: 12 Mar 2012
Online Status: Offline
Posts: 4
Quote Naithan Replybullet Posted: 13 Mar 2012 at 3:52am
Thanks for the reply,
 
I changed your formula as shown and it gives a "boolean is required here"
error message.
 
left({Part.Part_Prim_Desc},len({Part.Part_Prim_Desc})-3)
 
Cant work out why this would be. Help would be appreciated as I'm fairly new to Crystal (2008)
 
Naithan
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Mar 2012 at 4:30am
did you put this in the select expert?
The select expert is only used to select rows based on a boolean evaluation.
go to the field explorer,
right click on formula fields,
select new,
enter a name,
put the formula there
save it
drag and drop the formula onto the report
IP IP Logged
Naithan
Newbie
Newbie
Avatar

Joined: 12 Mar 2012
Online Status: Offline
Posts: 4
Quote Naithan Replybullet Posted: 13 Mar 2012 at 10:37pm
Oh that works almost perfect, thanks.
 
Only one issue to deal with is that it gives an error of "string length is less than 0 or not an integer". I presume this is because in some cases there is no data to apply the formula too. So what is the best way of dealing with that whilst keeping the formula active?
 
Much thanks for your help
 
Naithan Smile
Naithan
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Mar 2012 at 3:55am
depends on what you want to return if the string is less than 3 characters (or empty). This emaple returns the orginal string
 
if len({Part.Part_Prim_Desc})<3 then {Part.Part_Prim_Desc}
else
left({Part.Part_Prim_Desc},len({Part.Part_Prim_Desc})-3)
IP IP Logged
Naithan
Newbie
Newbie
Avatar

Joined: 12 Mar 2012
Online Status: Offline
Posts: 4
Quote Naithan Replybullet Posted: 14 Mar 2012 at 4:05am
That works great,
 
Thanks very much for your help,
 
Much appreciated
 
NaithanSmile
Naithan
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.031 seconds.