Ambiguity in string.slice()

#1

I just noticed what I believe is an ambiguity in the documentation for string.slice()

It states:

Squirrel continues copying characters one after the other from this point onward until it reaches either the end of the source string or the index specified as the method’s optional second parameter.

If I set the optional index to be beyond the end of the string, I’d expect it to return only up to the actual end of the string. Instead, it raises an exception.

testStr <- "01234"
server.log(testStr.slice(0,3))  // works
server.log(testStr.slice(0,6))  // fails

I’m not saying that the behaviour of string.slice is wrong, I think the docs need to be more explicit. :slight_smile:

0 Likes

#2

Fixed. And I took the opportunity to update the array.slice() doc, which had the same ambiguity.

0 Likes