How to replace brackets in strings

前端 未结 4 473
孤城傲影
孤城傲影 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:42

    You can remove the curly brackets with .replaceAll() in a line with square brackets

    String newString = originalString.replaceAll("[{}]", "X")

    eg: newString = "ARG:token_name"

    if you want to further separate newString to key and value, you can use .split()

    String[] arrayString = newString.split(":")

    With arrayString, you can use it for your HashMap with .put(), arrayString[0] and arrayString[1]

提交回复
热议问题