Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 替换“\&引用;一串_Java_Android - Fatal编程技术网

Java 替换“\&引用;一串

Java 替换“\&引用;一串,java,android,Java,Android,我有一个URL字符串 http:\/\/a0.twimg.com\/profile_images\/2170585961\/ETimes_normal.png 我想用“替换”,但我使用: String.replaceAll("\",""); 显示错误。我该怎么办 (从key profile\u image\u url检索)改用,它会回复所有出现的内容 str = str.replace("\\", ""); 从你的例子来看: String u = "http:\\/\\/a0.twim

我有一个URL字符串

http:\/\/a0.twimg.com\/profile_images\/2170585961\/ETimes_normal.png
我想用
替换
,但我使用:

String.replaceAll("\","");
显示错误。我该怎么办


(从key profile\u image\u url检索)

改用,它会回复所有出现的内容

str = str.replace("\\", "");

从你的例子来看:

String u = "http:\\/\\/a0.twimg.com\\/profile_images\\/2170585961\\/ETimes_normal.png";
System.out.println(u.replace("\\",""));
产出:

http://a0.twimg.com/profile_images/2170585961/ETimes_normal.png

请注意,该方法采用正则表达式,在这种情况下,您不需要它。

使用它,它会回复所有出现的情况

str = str.replace("\\", "");

从你的例子来看:

String u = "http:\\/\\/a0.twimg.com\\/profile_images\\/2170585961\\/ETimes_normal.png";
System.out.println(u.replace("\\",""));
产出:

http://a0.twimg.com/profile_images/2170585961/ETimes_normal.png


请注意,该方法采用正则表达式,在这种情况下,您不需要它。

用另一个反斜杠转义反斜杠:

String.replaceAll("\\\\","");

由于第一个参数是正则表达式,因此应该有两个反斜杠(
\
是正则表达式中的特殊字符)。但它也是一个字符串,所以每个反斜杠都应该转义。因此有四个
\
s.

用另一个反斜杠转义反斜杠:

String.replaceAll("\\\\","");

由于第一个参数是正则表达式,因此应该有两个反斜杠(
\
是正则表达式中的特殊字符)。但它也是一个字符串,所以每个反斜杠都应该转义。所以有四个
\
s.

我使用replace,它也是错误的,因为“\”是一个特殊字符。@user1423447:您需要引用它(使用另一个反斜杠“\”),请参阅我的更新。。您必须使用以下代码:String.replaceAll(“/”,”);你错了。在您的url中没有任何“\”@AliSh:他想替换
“\”
@user1423447:解决方案仍然有效,并用示例进行了更新。我使用replace,它也会出错,因为“\”是一个特殊字符。@user1423447:您需要引用它(使用另一个反斜杠“\”),请参阅我的更新。。您必须使用以下代码:String.replaceAll(“/”,”);你错了。在你的url中没有任何“\”@AliSh:他想替换
“\”
@user1423447:解决方案仍然有效,并用示例进行了更新。在你的字符串中,are not“\”the are some“/”,我想这就是问题所在,但请你编辑你的qeustion,并添加错误消息?在你的字符串中,are not“\”the are some“/”,我认为这就是问题所在,但请您编辑您的qeustion,并添加错误消息?很好,但现在它可以工作,但看起来很难看。:)(还原为-1)但请使用
replace
方法,因为您通常不需要正则表达式…很好,但现在它可以工作,但看起来很难看。:)(还原为-1)但请使用
replace
方法,因为您通常不需要正则表达式。。。