Extract substring from a string

后端 未结 10 1944
栀梦
栀梦 2020-12-02 19:55

what is the best way to extract a substring from a string in android?

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 20:06

    substring(int startIndex, int endIndex)

    If you don't specify endIndex, the method will return all the characters from startIndex.

    startIndex : starting index is inclusive

    endIndex : ending index is exclusive

    Example:

    String str = "abcdefgh"

    str.substring(0, 4) => abcd

    str.substring(4, 6) => ef

    str.substring(6) => gh

提交回复
热议问题