Extract substring from a string

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

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

10条回答
  •  半阙折子戏
    2020-12-02 20:11

    If you know the Start and End index, you can use

    String substr=mysourcestring.substring(startIndex,endIndex);
    

    If you want to get substring from specific index till end you can use :

    String substr=mysourcestring.substring(startIndex);
    

    If you want to get substring from specific character till end you can use :

    String substr=mysourcestring.substring(mysourcestring.indexOf("characterValue"));
    

    If you want to get substring from after a specific character, add that number to .indexOf(char):

    String substr=mysourcestring.substring(mysourcestring.indexOf("characterValue") + 1);
    

提交回复
热议问题