How to Replace dot (.) in a string in Java

后端 未结 4 1782
[愿得一人]
[愿得一人] 2020-11-28 12:26

I have a String called persons.name

I want to replace the DOT . with /*/ i.e my output will be persons/*/name

4条回答
  •  -上瘾入骨i
    2020-11-28 12:59

    Use Apache Commons Lang:

    String a= "\\*\\";
    str = StringUtils.replace(xpath, ".", a);
    

    or with standalone JDK:

    String a = "\\*\\"; // or: String a = "/*/";
    String replacement = Matcher.quoteReplacement(a);
    String searchString = Pattern.quote(".");
    String str = xpath.replaceAll(searchString, replacement);
    

提交回复
热议问题