Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.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_String - Fatal编程技术网

Java 替换不工作的子字符串

Java 替换不工作的子字符串,java,string,Java,String,它应该非常简单 我有这个字符串: INS113457消息响应xmlns=”httptt://www.ins113457.org/ins113457/" I wnat替换字符串的一部分-I使用: reponse_str = new String(response).replace(" xmlns=\"httptt:////www.ins113457.org//ins113457//\"", ""); reponse_str = new String(response).replace(" x

它应该非常简单

我有这个字符串:

INS113457消息响应xmlns=”httptt://www.ins113457.org/ins113457/"

I wnat替换字符串的一部分-I使用:

reponse_str = new
 String(response).replace(" xmlns=\"httptt:////www.ins113457.org//ins113457//\"", "");

reponse_str = 
new String(response).replace(" xmlns=\"httptt://www.ins113457.org/ins113457/\"", "");
但两者都不起作用

预期输出为
ins113457MessageResponse

可能有什么问题?

您应该使用:

reponse_str = new String(response).replace(" xmlns=\"httptt://www.ins113457.org/ins113457/\"", "");
/
未被替换为
/

\
被替换为
\

我测试了两者

第一个不起作用,但这是因为所有斜杠都有两次,所以
replace
方法找不到字符串。当我移除它们时,效果很好

您不需要将斜杠加倍,因为它们在Java字符串中没有任何特殊作用,但反斜杠用于转义特殊字符,因此您需要将其转义


但是我不能告诉你第二个函数,因为它按预期工作。

预期的输出是什么?这是预期的输出:ins113457MessageResponseI建议你尝试使用较小的子字符串函数。变量
响应的类型和值是什么?将原始字符串和子字符串的每个字符转储为整数,并寻找差异。