substring question

nate100

Member
I have string with the following value:

633598642076131250

How do I get the last 4 characters only with woudl be 1250 ?

Thank you.
 

sunilnair

Member
substring('633598642076131250',length('633598642076131250') - 3 , 4).

you can use this for any string variable where you need the last 4 characters .


Cheers
Sunil.
 

jongpau

Member
Or to make it a little more robust:

Code:
DEFINE VARIABLE a AS CHARACTER NO-UNDO.
DEFINE VARIABLE b AS CHARACTER NO-UNDO.
a = '633598642076131250'.
b = IF LENGTH(a) GT 3 THEN SUBSTRING(a,LENGTH(a) - 3) ELSE a.
MESSAGE b VIEW-AS ALERT-BOX.

That way it will not "die" when the string gets shorter than the required 4 characters. Also note that you do not *have* to specify the 4 as you are after the last x characters anyway.
 
Top