Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract 2 characters from string

Status
Not open for further replies.

kwirky

MIS
Apr 22, 2010
85
AU
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 :(
 
stringvar x := {MainEstimateDetails.JobDescription};
stringvar array y := split(x," ");
numbervar i;
numbervar j := ubound(y);
numbervar k := 0;
for i := 1 to j do (
if y like "*pp" then
k := left(y,instr(y,"pp")-1)
);
k

-LB
 

I think you'll need to trap for words ending in "pp" that are not the "pp" you're looking for. Also, the final assignment of numbervar k needs to be converted to a number.

stringvar x := "Annppual App Report 25496pp & Cover 12345";
stringvar array y := split(x," ");
numbervar i;
numbervar j := ubound(y);
numbervar k := 0;
for i := 1 to j do (
if y like "*pp"
and isnumeric(mid(y,len(y) - 2,1))
then
k := tonumber(left(y,instr(y,"pp")-1))
);
k

 
Thanks for the correction making the value a number. I should have tested it. I am having trouble thinking of any words that end in "pp", so please name three :). Maybe some names/proper nouns: Von Trapp, Al Capp, Lapp.

-LB
 

App is the first thing that came to mind, although it's not a real word - there are actually only four:

repp
schlepp
shlepp
typp

But I would hate for Kwirky to screw up the Von Trapp Family Annual Report.

More to the point, we've all decided to not trap for things that could 'never happen', but then do...

 
The last two weren't in my OED (1993 version), but I'll believe you anyway. I thought of "app" but discounted it as not a real word, but I suppose it is. Anyway, it certainly doesn't hurt to check, and it might be helpful. It turns out that Merriam-Webster online says there are 19 that meet this criterion, though they include some abbreviations.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top