Replace a String between two Strings

前端 未结 6 1934
说谎
说谎 2020-12-07 00:32

Let\'s say we have something like:

&firstString=someText&endString=OtherText

And I would like to replace \"someText\" with somethin

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 01:34

    As I understood the question, you should do something like this, but I'm not sure I totally got what you asked:

    yourString = firstString + replacingString + endString;
    

    If you want the "replaced" string:

    replacedString = wholeString.substring(0, wholeString.lastIndexOf(endString) - 1);
    replacedString = tempString.substring(firstString.length() + 1);
    

提交回复
热议问题