Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Extracting from a string Post Reply Post New Topic
Author Message
Gian Luca
Newbie
Newbie
Avatar

Joined: 20 Oct 2010
Location: Italy
Online Status: Offline
Posts: 6
Quote Gian Luca Replybullet Topic: Extracting from a string
     Posted: 09 Feb 2011 at 4:57am
Hi all,
I am trying to extract a code of 6 chrs from a very long text string that contains different info. This code is not always at the same place along the string  but always starts with a "3" or with an "N".
How can I define a Formula Field as to extract this code from the string?
Thanks a lot for your help.
G
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 10 Feb 2011 at 3:45am
Try something like this:
 
NumberVar location;
location := InStr({table.field}, ' 3')
if location <= 0 then
  location := InStr({table.field}, ' N')
if Location >= 0 then
  mid({table.field}, location + 1, 6)
else ''
 
This will only work if there are no other "words" in the field that start with 3 or N.
 
-Dell
IP IP Logged
Gian Luca
Newbie
Newbie
Avatar

Joined: 20 Oct 2010
Location: Italy
Online Status: Offline
Posts: 6
Quote Gian Luca Replybullet Posted: 10 Feb 2011 at 10:43pm
Thanks hilfy,
I get an error message saying that the part starting from .. "if location <=0 then ...etc etc" ... is not part of the formula.
IP IP Logged
Gian Luca
Newbie
Newbie
Avatar

Joined: 20 Oct 2010
Location: Italy
Online Status: Offline
Posts: 6
Quote Gian Luca Replybullet Posted: 10 Feb 2011 at 10:48pm
Sorry.. a couple of semicolomns were missing   ;-) .. it works fine!
Thanks again
IP IP Logged
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