[SOLVED] How do I put the last four characters of a field (string) in a new variable?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

[SOLVED] How do I put the last four characters of a field (string) in a new variable?

Post by karmacomposer » Thu Jul 19, 2018 11:37 pm

I tried searching all over the internet for the answer and just could not find it.

I have a SSN field and I need to grab the last four digits and append it to another field (making a complete account number).

The SSN field already has a script for proper formatting of the SSN (thank you to the person who helped me with that) and it uses RawKeyDown to do its magic. Do I add this there, after the RawKeyDown, on CloseField or do I put it in the script of the account # field? My thought is, I don't want to break what the auto-formatting is doing.

Also, when reading back the data, how do I hide all but the last four digits with either a "*" or a bullet?

Thank you for your help.

Mike
Last edited by karmacomposer on Fri Jul 20, 2018 1:39 am, edited 1 time in total.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How do I put the last four characters of a field (string) in a new variable?

Post by bogs » Thu Jul 19, 2018 11:44 pm

If the ssn is formatted as you say, you could always just set the itemDelimiter (dictionary) to - or / or whatever you used for the formatting, then get item 3 of the field, which should be the last 4 numbers. You could also (if it isn't actually formatted) grab chars 6 to 9 of the field (characters, keyword, dictionary).

The code would look like -

Code: Select all

// formatted ssn...
set the itemDelimiter to "-"
put item 3 of field "yourSsnField" into tmpLastFour
// your code for what you want to do with that...
Selection_003.png
Formatted item 3...
...and unformatted -

Code: Select all

put char 6 to 9 of field "yourSsnField" into tmpLastFour
// your code for what you want to do with that...
Selection_004.png
Unformatted char...
Image

karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

Re: How do I put the last four characters of a field (string) in a new variable?

Post by karmacomposer » Fri Jul 20, 2018 1:39 am

Thank you. That was perfect! The 1st option worked a treat.

Mike

Post Reply

Return to “Talking LiveCode”