remove substring in a string without using regex (cannot use replaceAll)

前端 未结 5 1756
深忆病人
深忆病人 2021-01-28 04:32

I need to remove some substrings in strings (in a large dataset). The substrings often contain special characters, like these: ., ^, /,... and replaceAll() would treat them as s

5条回答
  •  不要未来只要你来
    2021-01-28 05:04

    There are 2 methods named replace in the String class that perform replacement without treating their parameters as regular expressions.

    One replace method replaces one char with another char.

    The other replace method replaces a CharSequence (usually a String) with another CharSequence.

    Quoting the Javadocs from the second replace method:

    Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.

提交回复
热议问题