Java不与正则表达式\的工作,说:无效的转义序列序列、不与、工作、正则表达式

2023-09-12 09:45:02 作者:黑野川鹤.

我要与SS是+和所有的SS替换所有空格字符的字符串...它可以很好地用于SS,但不知何故,日食不会让我用\ S的一个空格..我试过\ t的替代,但它也不行。我得到以下错误:

I want to replace all whitespace characters in a string with a "+" and all "ß" with "ss"... it works well for "ß", but somehow eclipse won't let me use \s for a whitespace.. I tried "\t" instead, but it doesn't work either.. I get the following error:

无效的转义序列(有效问卷   是\ B \吨\ñ\ F \ r \\'\)

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

这是我的code:

try {
    String temp1 = from.getText().toString();
    start_from  = temp1.replaceAll("ß", "ss");
    start_from  = start_from.replaceAll("\s", "+");
}

为什么不工作?是它与Android,Eclipse或有什么问题呢?

why doesn't it work? is it a problem with android, eclipse or what?

在此先感谢!

推荐答案

您需要逃避斜线

start_from  = start_from.replaceAll("\\s", "+");