Print Page | Close Window

Formula to delete character from string

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4172
Printed Date: 28 Apr 2024 at 11:00pm


Topic: Formula to delete character from string
Posted By: taskhill
Subject: Formula to delete character from string
Date 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




Replies:
Posted By: ezeney
Date 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'.


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


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


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


Posted By: Mojoflow1000
Date Posted: 18 Feb 2014 at 11:23am

< please disregard > 



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



Print Page | Close Window