How to replace brackets in strings

前端 未结 4 509
孤城傲影
孤城傲影 2021-01-14 22:44

I have a list of strings that contains tokens.
Token is:

{ARG:token_name}.

I also have hash map of tokens, where key is th

4条回答
  •  悲&欢浪女
    2021-01-14 23:40

    String.replaceAll() works on regexps. {n,m} is usually repetition in regexps.

    Try to use \\{ and \\} if you want to match literal brackets.

    So replacing all opening brackets by X works that way:

    myString.replaceAll("\\{", "X");
    

    See here to read about regular expressions (regexps) and why { and } are special characters that have to be escaped when using regexps.

提交回复
热议问题