Replacing double backslashes with single backslash

后端 未结 7 1263
终归单人心
终归单人心 2020-12-18 04:21

I have a string \"\\\\u003c\", which belongs to UTF-8 charset. I am unable to decode it to unicode because of the presence of double backslashes. How do i get \"\\u003c\" fr

7条回答
  •  天涯浪人
    2020-12-18 04:43

    Another option, capture one of the two slashes and replace both slashes with the captured group:

    public static void main(String args[])
    {
        String str = "C:\\\\";
        str= str.replaceAll("(\\\\)\\\\", "$1");
    
        System.out.println(str);
    } 
    

提交回复
热议问题