Copy the last 6 characters in a string.

Dman

Active Member
Licensed User
Longtime User
If I have an edittext that contains anywhere from 8 to 17 characters, how would I copy the last 6 to another edittext? I know how to start from the xth position from the beginning, but I can't seem to figure out how to start from the end.
 

Dman

Active Member
Licensed User
Longtime User
Thank you. Using the code below, if I enter the numbers 12345678 and click the Last 6 button, I get 3456

B4X:
txtStockNum.Text = txtVIN.Text.SubString2(txtVIN.Text.Length-6,6)

But if I click on the last 8 button I get 12345678 using this code
B4X:
txtStockNum.Text = txtVIN.Text.SubString2(txtVIN.Text.Length-8,8)

But if I enter 12345678901234567 I get an error when clicking the Last 6 button stating
Stringindexoutofboundsexception:
length = 17; regionStart = 11; regionlength = 5

And if I click on the last 8 button I get this error.
Stringindexoutofboundsexception:
length = 17; regionStart = 9; regionlength = 1
 
Upvote 0
Top