Code Select
Lbl SubStr
.SubStr(str,begin,len)
Copy(r1+r2,L4,r3)
0->{r1+r2+r3}
Return L4
If you embed this code in your program, then you can call SubStr( (type this out yourself, there is no token for it) and it will return a fraction of the string supplied in the first argument, starting from the supplied begin index (0 is the start) and len chars long.
This code uses the Copy( command to copy the desired part of the string to the TempSwapArea (L4) (so if you use this for data storage you'll have to change it to another free RAM area) and adds a 0 byte at the end (to allow axe to see where the string ends). When using this code, make sure that the length is never bigger than 255 and that you never ask for a string with a length of 0 (both could cause a crash).
Example:
Code Select
Text SubStr("JOHNRODNEYKYLESIDNEYMICHAEL",4,6)
This should draw the text "RODNEY" to the screen.
However if you just want to use it for a list of strings, then you might want to define your strings like this instead:
Code Select
Data(Str000^r,Str001^r,Str002^r,Str003^r,Str004^r,Str005^r,Str006^r)->°SLIST
"JOHN"->Str000
"RODNEY"->Str001
"KYLE"->Str002
"SIDNEY"->Str003
"MICHAEL"->Str004
"BEN"->Str005
"JAKE"->Str006
When you define your strings like this, then you can get each string of the list by doing {I*2+°SLIST}^r where I is the index of the string you want (with 0 being the first string). This method works similar to how an array of strings works internally in higher level programming languages.
Example:
Code Select
Text {2*2+°SLIST}^r
This should draw the text "KYLE".
EDIT: fixed incorrect code