Remove part of string in Java

后端 未结 12 1739
遥遥无期
遥遥无期 2020-11-28 04:22

I want to remove a part of string from one character, that is:

Source string:

manchester united (with nice players)

Target string:

12条回答
  •  死守一世寂寞
    2020-11-28 04:56

    Using StringBuilder, you can replace the following way.

    StringBuilder str = new StringBuilder("manchester united (with nice players)");
    int startIdx = str.indexOf("(");
    int endIdx = str.indexOf(")");
    str.replace(++startIdx, endIdx, "");
    

提交回复
热议问题