How to Trim Number from Variable in AppleScript

applescripttrim

Is it possible to trim a number to only keep the last 3 numbers ?

For exemple a phone number save in the variable, and I would like to keep the last 3 digit.

Kind regards

Best Answer

Here's one way. We set a variable called "the_phone_number" to some value, then pick off the last three characters. You can probably tell by inspection that it would be easy to modify this script to get the last four, or last two, or whatever.

set the_phone_number to "424-354-3548"
set the_last_three to characters -3 thru -1 of the_phone_number as string