Help! Extracting substrings

I need some help. How do you extract a substring from the end of a string. I know, e.g. that if a$ = "Smith" then Let b$ = a$[1:3] would be "Smi". I also know that a$ = "Smith" then Let b$ = a$[3:5] would be "ith", but how do you extract the last 3 letters from an unknown length of string?

Comments

Re: substring extracting ...

lowrieh1 & Big John ... One doesn't need two program lines for this one. Try this instead:

let b$=[len(a$)-2:len(a$)]

Regards ... Tom M

An even better line of code is:

let alast3$=[len(a$)-2:len(a$)]

This line associates a$ and its last-3-character substring - and avoids trampling on the string variable b$, which may be used somewhere else in the TB program listing. Regards ... Tom M

Tom M

Thanks for that m8. Much appreciated

Extracting string

Find the length of the string by using the following
LET x=len(a$)
Then use the value in x.
LET b$=a${3:x}

Chris

Extracting String

Thanks for that,

However, unless I'm missing something that would only work for a 5 character string as it seems to print from character 3 till the end of the string, i.e. my own surname has 6 characters and this prints the last 4.

Last three characters

Hi,

To extract the last three characters use:
LET x=len(a$)
Then use the value in x.
LET b$=a$[x-2:x]

Big John

Big John

Thanks for that,

That's the one that does the job. Much appreciated.