Print Page | Close Window

Trim a sentence in a 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=16098
Printed Date: 30 Apr 2024 at 3:06am


Topic: Trim a sentence in a String
Posted By: achandana01
Subject: Trim a sentence in a String
Date Posted: 04 Apr 2012 at 12:03pm
Hi,
 
I do have the strings
 
city new york
Los Angeles
city San Francisco
 
I would like to trim prefix "city" for strings which has city as theirt prefix and leave rest like they are
 
Finally data should look like this
 
new york
Los Angeles
San Francisco
 
Thanks


-------------
chand



Replies:
Posted By: kevlray
Date Posted: 09 Apr 2012 at 8:19am
formula:

If left({city_field},4) ="city" then right({city_field},len({city_field})-5)
else {city_field}

Not tested, but should work.


Posted By: lockwelle
Date Posted: 09 Apr 2012 at 11:22am
been answered, but how bout this..
 
if left({table.field}, 4 ) = "city " then
  mid ({table.field}, 6)
else
 {table.field}


Posted By: kevlray
Date Posted: 10 Apr 2012 at 4:27am
I always thought you had to have a length with the mid statement (or is that just for old BASIC code).


Posted By: rkrowland
Date Posted: 10 Apr 2012 at 4:43am

I know length is optional in Crystal, in fact the only thing I know of where you need to declare the length/number of characters for mid is Excel, and even then you can get round it by entering a high amount of characters

- eg =mid(a1,3,9999).
 
Regards,
Ryan.


Posted By: lockwelle
Date Posted: 10 Apr 2012 at 7:44am
even old BASIC, you just needed the starting point...at least from vb3 or so on....maybe even QB4
.Net is the same way...if you don't specify length, it is everything from the start to the end of the string.
 
TSQL wants a length, but you use the same trick the rkrowland said...just put in a large value.


Posted By: kevlray
Date Posted: 10 Apr 2012 at 11:36am
When I mean old BASIC, I am talking Apple II, Commodore 64 days. :-)



Print Page | Close Window