Java replace only first occurrence of a substring in a string

后端 未结 3 653
南笙
南笙 2020-12-11 20:23

This is somehow a duplicate of this problem Ruby - replace the first occurrence of a substring with another string just in java.

Problem is:

I have a string:

3条回答
  •  抹茶落季
    2020-12-11 21:01

    You should use already tested and well documented libraries in favor of writing your own code!

    StringUtils.replaceOnce("aba", "a", "")    = "ba"
    

    (copied from How to replace string only once without regex in Java?)

提交回复
热议问题