Technical Questions
 Crystal Reports Forum : Crystal Reports 9, X, XI, 2008, 2011 : Technical Questions
Message Icon Topic: Extract 2 characters from string Post Reply Post New Topic
Author Message
Kwirky
Newbie
Newbie
Avatar

Joined: 21 Apr 2010
Online Status: Offline
Posts: 32
Quote Kwirky Replybullet Topic: Extract 2 characters from string
    Posted: 01 Dec 2010 at 5:51pm
Hello,
Can anyone help to create a formula to extract 2 characters from the left of "pp" in a field using CR XI?

Field = {MainEstimateDetails.JobDescription} (string)

Sample string details:

"Annual Report 96pp & Cover 12345"  - want to be able to show only 96 (from 96pp)
"CTP A4 4pp" - want to be able to show only 4 (from 4pp)

The string length is variable and the "pp" will be in different places each time.

It is probably very simple, but I cannot get it :(
IP IP Logged
lockwelle
Senior Member
Senior Member


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4094
Quote lockwelle Replybullet Posted: 02 Dec 2010 at 4:07am

mid( {MainEstimateDetails.JobDescription}, instr( {MainEstimateDetails.JobDescription}, "pp") - 2, 2)

IP IP Logged
Kwirky
Newbie
Newbie
Avatar

Joined: 21 Apr 2010
Online Status: Offline
Posts: 32
Quote Kwirky Replybullet Posted: 02 Dec 2010 at 9:41am
Hi,
I get an error of "Start position is less than 1 or not an integer".
IP IP Logged
lockwelle
Senior Member
Senior Member


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4094
Quote lockwelle Replybullet Posted: 02 Dec 2010 at 10:22am
which means that the string doesn't have a "pp"
 
I would change it to something like:
 
local numbervar iStart := instr({table.field}, "pp");
if iStart > 0 then
 do the substring stuff
else
  handle the non value...may be optional
 
IP IP Logged
Kwirky
Newbie
Newbie
Avatar

Joined: 21 Apr 2010
Online Status: Offline
Posts: 32
Quote Kwirky Replybullet Posted: 02 Dec 2010 at 10:25am
Perfect!

I used
local numbervar iStart := instr({MainEstimateDetails.JobDescription}, "pp");
if iStart > 0 then
 mid( {MainEstimateDetails.JobDescription}, instr( {MainEstimateDetails.JobDescription}, "pp") - 2, 2)
else
  "no pp"
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.031 seconds.

FREE ADVANCED
Crystal Reports Training!

Plus, free bonus PDF cheat sheet! Advanced Crystal Reports Training Give Me Advanced Training!