Is SpannableString.setSpan () 2nd parm 0?

My empirical experiment shows that if I setSpan(o, start, end) from beginning to end of the line, where end is String.length() - 1 , the last character is not covered.

When I changed end to exactly String.length() , the whole line is covered and ... I do not even get an exception from abroad.

Unfortunately, there is nothing in the documentation for this particular problem.

Can you confirm my observation? (or prove I'm wrong?)

+6
source share
2 answers

end is exceptional. 0, 2 , for example, has everything: from 0 inclusive to 2 , excluding 0 and 1 .

+5
source

Most of the "final" indexes will be exclusive in practical terms. That is, the final index is one outside the index of the latter, whatever it is. If the SpannableString is one of the Android SDKs, then no, the documentation does not talk about this for the setSpan method, although this applies to other methods like subSequence .

+2
source

Source: https://habr.com/ru/post/887866/


All Articles