Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Formula to delete character from string Post Reply Post New Topic
Author Message
taskhill
Newbie
Newbie
Avatar

Joined: 05 Sep 2008
Location: United States
Online Status: Offline
Posts: 1
Quote taskhill Replybullet Topic: Formula to delete character from string
    Posted: 05 Sep 2008 at 11:14am

Good morning.  I am new to Crystal reports and need some help with a formula. 

 

What I am facing is I have a field in which data is being captured as 9-12A and I need the data to be 009-12A so I wrote:

 

if Length ({myString}) = 5 then "00" + {myString}

 

else if Length ({myString}) = 6 then "0" + {myString}

 

else {myString}

 

Now this works fine but I also need a way to delete the letter at the end of the string so it displays 009-12 only.

 

Is there a way to detect only a alpha character and delete it while not destroying the integrity of the existing formula?  I will even take a formula on a formula if that is possible.

 

Thanks in advance

 

Task



Edited by taskhill - 05 Sep 2008 at 11:43am
IP IP Logged
ezeney
Newbie
Newbie
Avatar

Joined: 05 Sep 2008
Location: United States
Online Status: Offline
Posts: 14
Quote ezeney Replybullet Posted: 05 Sep 2008 at 3:27pm
If you know for sure you always need the first 6 charaters, you can use 'Left(str, length)' function.
 
Since your {NewString} is '009-12A' now, Left({NewString}, 6) will give you '009-12'.
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 09 Sep 2008 at 12:02pm
Could you check the last character  ?  If it is alpha, drop it.  If not alpha, keep it.
 
if NumericText(mid(string,length(string)-1,1)) // is the last char numeric
then
      string                                                        // keep the whole string
else
      mid(string,1,length(string)-1)                   // drop the last character
IP IP Logged
spinsta
Newbie
Newbie


Joined: 26 Feb 2013
Location: United States
Online Status: Offline
Posts: 1
Quote spinsta Replybullet Posted: 26 Feb 2013 at 12:59pm
I do this and get the error message "The result of selection formula must be a boolean." am I doing something wrong?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Feb 2013 at 3:47am
sounds like youa re putting the formula in the select expert. That is only to include (true) or exclude (false) rows based on a boolean result from the formula.
You need to create a new formula field using the Field Explorer > Formula Fields.
IP IP Logged
Mojoflow1000
Newbie
Newbie
Avatar

Joined: 17 Feb 2014
Location: United States
Online Status: Offline
Posts: 7
Quote Mojoflow1000 Replybullet Posted: 18 Feb 2014 at 11:23am

< please disregard > 



Edited by Mojoflow1000 - 19 Feb 2014 at 8:11am
IP IP Logged
hello
Groupie
Groupie
Avatar

Joined: 05 Feb 2014
Online Status: Offline
Posts: 85
Quote hello Replybullet Posted: 19 Feb 2014 at 7:56am
Originally posted by DBlank

sounds like youa re putting the formula in the select expert. That is only to include (true) or exclude (false) rows based on a boolean result from the formula.
You need to create a new formula field using the Field Explorer > Formula Fields.


That, or he is not specifying the {mystring} field as the last line of code on a line by itself.
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.016 seconds.