Android Question How to remove that last character in a StringBuilder variable

ColorMan

Member
Licensed User
Given global StringBuilder variable sb one can Append new strings as sb.Append("string"). There is a complementary operator sb.Remove(FirstIndex, LastIndex) which can extract a string from the middle of a string. But the Guides say that the character position identified as LastIndex is not removed. The what is the process to remove only the character at the postion of LastIndex?
sb.Remove(LastIndex, LastIndex)?
 

emexes

Expert
Licensed User
the character at the position of LastIndex
The indexes point to "between the characters" rather than at them, which is sometimes confusing as fcuk but does have the nice property that the length of the string pointed to by two indexes is the numerical difference of the indexes. Thus (LastIndex, LastIndex) is not actually pointing at a character; it is pointing at the end boundary edge of the string, just after the last character.
 
Last edited:
Upvote 0
Top