Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SpannableString.setSpan() 2nd parm 0-based?

My empirical experiment shows that if I setSpan(o, start, end) from start to end of a string, where end is String.length() - 1, the last character isn't covered.

When I changed end to exactly String.length(), the entire string is covered and... I don't even get an "out-of-bound" exception.

Unfortunately, there is nothing in the documentation regarding this particular issue.

Can you confirm my observation? (or prove me wrong?)

like image 844
uTubeFan Avatar asked May 11 '11 18:05

uTubeFan


2 Answers

end is exclusive. 0, 2, for example, is everything from 0 inclusive to 2 exclusive which is 0 and 1.

like image 155
Ry- Avatar answered Oct 20 '22 00:10

Ry-


Most "ending" indexes will be exclusive as a matter of practice. That is, the ending index is one beyond the index of the last whatever-it-is. If SpannableString is the one from the Android SDK, then no, the documentation doesn't say this for method setSpan, though it does for other methods such as subSequence.

like image 35
Nathan Ryan Avatar answered Oct 19 '22 23:10

Nathan Ryan