Remove part of string in Java

后端 未结 12 1760
遥遥无期
遥遥无期 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:57

    You should use the substring() method of String object.

    Here is an example code:

    Assumption: I am assuming here that you want to retrieve the string till the first parenthesis

    String strTest = "manchester united(with nice players)";
    /*Get the substring from the original string, with starting index 0, and ending index as position of th first parenthesis - 1 */
    String strSub = strTest.subString(0,strTest.getIndex("(")-1);
    

提交回复
热议问题