String slice hard crash
-
Executing the following code crashes FUZE hard (termniate to the system menu):
s = "Hello World!" f = s[0:len(s)-2]
Workaround: Store the length in an intermediate variable:
s = "Hello World!" l = len(s) f = s[0:l-2]
What bothers me more than the crash is that, to cut off the last character of a string, I have to use
l-2
, notl-1
. That does not seem to fit with the index range philosophy in other places (array index goes from 0 tolen(array)-1
,for i = 0 to 10
goes from 0 to 9) and makes it impossible to get a zero length slice; s[0:0] is still one character. String and array slices are undocumented AFAIK, so you can still change that and nobody would have the right to complain if you break their code :) -
Oh, turns out
f = s[0:-2]
also works perfectly and returns s with the last character removed, no need to call len() at all. Still, gnarl, -2 instead of -1.... -
@Z-Mann apologies for the delayed response. We will look into it.