Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string slicing using len()
#2
It happens string slicing starts from 0 (not from 1). So it ranges from 0 to LEN(a$)-1.
If you want your program work OK, you should do:
Code:
let a$="hello world"
let l=len(a$)-1
for i = 1 to l:
    let a$=a$(to len(a$) - 2)
    print i, a$
next i

Notice also that FOR upper limit is evaluated ON EACH iteration (like C). So if len(a$) changes, the loop will shorten. So better use a temporary var l to store initial LEN(a$).

Arrays subscripts starts from 0 to N-1 (like in C). But this behavior can be changed using --sinclair or --array-base switch.

NOTE: I'm planning (for compatibility) an --string-base (so LEN and string-slicing will work exactly as in Sinclair BASIC, by specifying --string-base=1). Also with FOR, stating --constant-for etc...
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)