简体   繁体   English

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

[英]Remove special character from string?

i have String like 我喜欢String

Join our<\/strong>\u00a0<strong>&#8220;Worldwide Host Your Own Screening Tour!

and i want 而且我要

Join our Worldwide Host Your Own Screening Tour!

My Code:: 我的代码::

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

Error 错误

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

Try this: 尝试这个:

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

String.replaceAll expects an RegEx. String.replaceAll需要一个RegEx。

You could use StringUtils too (it is a bit simple): 你也可以使用StringUtils (它有点简单):

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

Try it. 试试吧。

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

Francisco wins. Francisco赢了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM