从字符串中删除特殊字符?

时间:2012-07-12 13:33:41

标签: java string

我有像

这样的字符串
Join our<\/strong>\u00a0<strong>&#8220;Worldwide Host Your Own Screening Tour!

我想要

Join our Worldwide Host Your Own Screening Tour!

我的代码::

String str = "Join our<\/strong>\u00a0<strong>&#8220;Worldwide Host Your";
System.out.println(str.replaceAll("<\/strong>\u00a0<strong>&#8220;", " "));

错误

 Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

2 个答案:

答案 0 :(得分:1)

试试这个:

String str = "Join our<\\/strong>\u00a0<strong>&#8220;Worldwide Host Your";
System.out.println(str.replaceAll("<\\\\/strong>\\u00a0<strong>&#8220;", " "));

String.replaceAll需要一个RegEx。

您也可以使用StringUtils(这有点简单):

StringUtils.replace(str, "<\\/strong>\u00a0<strong>&#8220;", "")

答案 1 :(得分:1)

试试吧。

    String s="Join our<\\/strong>\u00a0<strong>&#8220;Worldwide Host Your Own Screening Tour!";
    System.out.println(s.replaceAll("<\\\\/strong>\\u00a0<strong>&#8220;", " "));

弗朗西斯科获胜。