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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove beginning and ending of a string, keep a portion 6

Status
Not open for further replies.

NewToThis2

Technical User
Mar 30, 2004
62
US
Using CV9.
I have a field called Key-String in which I only need digits 5, 6, 7 and 8th from the right. The field will contain various different numbers of digits but I will always need only the 5th, 6th, 7th and 8th digits from the right. So for this example, I only want to see 3535. Here's a sample string:
E00062904MGRCHGSTAT0000035350001. Could someone please help me with the formula? Thanks so much!
 
For Crystal 8.5, one can use
Code:
mid({Key-String}, 24, 4)

This should also work in higher version, but not if the string itself is variable. If it is, try a pair of formulae:
Code:
Right({Key-String}, 8)
   
Left(@Right-key, 4)

Madawc Williams (East Anglia)
 
Or, try the following which allows for different lengths, as long as the characters of interest are always the four digits starting from the 8th position from the right:

strreverse(mid(strreverse({table.key-string}),5,4))

-LB
 
Or:

Mid({table.field},len(trim({table.field}))-5)

This will also allow for padded fields, so if there are spaces it will still work.

-k
 
SV,

I think you mean:

Mid({table.field},len(trim({table.field}))-7,4)

-LB
 
Ahhh, right you are, LB, I should have read it more closely, too busy these days, thanks.

-k
 
Thanks so much everyone. I tried them all. The only one I could get to work was this one:
strreverse(mid(strreverse({table.key-string}),5,4))

A couple of the others brought back this message:
Start position is less than 1 or not an integer.

Thanks again everyone - I got what I needed as I always do whenever I ask a question in this forum. Thanks so much to all of you experts out there who are so willing to help.
 
I know it's 5 days later, but another option:

left(right({Key-string},8),4)

It's a single formula version of Madawc's second suggestion.

Mike
 
Thanks so much mbarron. It worked like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top