Print Page | Close Window

Removing data at the right of a string

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Tips and Tricks
Forum Discription: Have you learned some great tricks to share with the group? Post them here!
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15860
Printed Date: 02 May 2024 at 3:14am


Topic: Removing data at the right of a string
Posted By: Naithan
Subject: Removing data at the right of a string
Date 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



Replies:
Posted By: DBlank
Date Posted: 13 Mar 2012 at 3:41am
left(field,len(field)-3)


Posted By: Naithan
Date 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


Posted By: DBlank
Date 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


Posted By: Naithan
Date 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


Posted By: DBlank
Date 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)


Posted By: Naithan
Date Posted: 14 Mar 2012 at 4:05am
That works great,
 
Thanks very much for your help,
 
Much appreciated
 
NaithanSmile


-------------
Naithan



Print Page | Close Window