How to escape the double quotes in java not as \" but \\u0022

I have a string which has the value String s="D"Souza"

Now before sending this i want to replace " with u022 as a requirement. How to do this ?

    public static String escapeJS(String string) {
        String escapes[][] = new String[][]{
                {"", "\"},
                {""", "u0022"},
                {"n", "n"},
                {"r", "r"},
                {"b", "b"},
                {"f", "f"},
                {"t", "t"}
        };
        for (String[] esc : escapes) {
            string = string.replace(esc[0], esc[1]);
        }
        return string;
    }
}

But here after escaping when we pass this to a library the string we get conatins u0022 instead of quotes.

Any suggestions how to use the escaping correctly.

Note the library does not process correctly( basically a bug in it) " and hence we try to use u0022

链接地址: http://www.djcxy.com/p/20582.html

上一篇: 源代码中遇到过的最好的评论是什么?

下一篇: 如何在java中避免双引号而不是\“但是\\ u0022