Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
PatternSyntaxException:在java中使用String.ReplaceAll函数时?_Java_Regex_String_Junit - Fatal编程技术网

PatternSyntaxException:在java中使用String.ReplaceAll函数时?

PatternSyntaxException:在java中使用String.ReplaceAll函数时?,java,regex,string,junit,Java,Regex,String,Junit,我在尝试执行String.ReplaceAll时遇到patternsyntax异常 下面是我的字符串 Number of testcases to execute : 39? Starting execution of test case : testCreateDAta? The class that has completed its execution is : test.com.mySpace.service.ejb.session.MyTest? Finished

我在尝试执行String.ReplaceAll时遇到patternsyntax异常

下面是我的字符串

Number of testcases to execute : 39?    Starting execution of test case : testCreateDAta?    The class that has completed its execution is : test.com.mySpace.service.ejb.session.MyTest?     Finished execution of test case : testCreateDAta?    Starting execution of test case : testUpdate?
我想做的是:

junitReportString.replaceAll("?", "\n"); 
上述代码为我获取了以下异常:

java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0 
然后我用下面的代码再次尝试:

junitReportString.replaceAll("\\?", "\n"); 
上面的代码获取的字符串与上面提到的相同

我的完整代码:

String junitReportString=new String();
myApp= new URL("http://localhost:port/testWeb/TestJunit.jsp");
URLConnection yc = myApp.openConnection();
yc.connect();
junitReportString=yc.getHeaderField("finalJUNITReport").toString();
System.out.println(junitReportString);
junitReportString.replaceAll("\\?", "\n");
System.out.println("Report Details     ==============>"+junitReportString);
我的代码有什么问题。非常感谢任何指导。

不会更改实际的
字符串
它只返回包含更改的新
字符串

junitReportString=junitReportString.replaceAll("\\?", "\n"); 
//Now you have changed String
不更改实际的
字符串
它只返回包含更改的新
字符串

junitReportString=junitReportString.replaceAll("\\?", "\n"); 
//Now you have changed String
不更改实际的
字符串
它只返回包含更改的新
字符串

junitReportString=junitReportString.replaceAll("\\?", "\n"); 
//Now you have changed String
不更改实际的
字符串
它只返回包含更改的新
字符串

junitReportString=junitReportString.replaceAll("\\?", "\n"); 
//Now you have changed String


您的代码
replaceAll(“\\?”,“\n”)对我有效..我无法打印新行中的字符串:(你能发布你的完整代码吗?我想我知道发生了什么。你需要将字符串赋回到变量:
junitReportString=junitReportString.replaceAll(“\\?”,“\n”);
@AvinashRaj:我已经发布了我的全部代码。你的代码
replaceAll(“\\?”,“\n”);
对我有效。我无法在新行打印字符串。:(你能发布你的完整代码吗?我想我知道发生了什么。你需要将字符串赋回到变量:
junitReportString=junitReportString.replaceAll(“\\?”,“\n”);
@AvinashRaj:我已经发布了我的全部代码。你的代码
replaceAll(“\\?”,“\n”);
对我有效。我无法在新行打印字符串。:(你能发布你的完整代码吗?我想我知道发生了什么。你需要将字符串赋回到变量:
junitReportString=junitReportString.replaceAll(“\\?”,“\n”);
@AvinashRaj:我已经发布了我的全部代码。你的代码
replaceAll(“\\?”,“\n”);
对我有效。我无法在新行打印字符串。:(你能发布你的完整代码吗?我想我知道发生了什么。你需要将字符串赋回到变量:
junitReportString=junitReportString.replaceAll(“\\?”,“\n”);
@AvinashRaj:我已经发布了我的全部代码。天哪……我太傻了……谢谢老兄……你的目标是..B-)天哪…我太傻了…谢谢老兄..在目标上你太傻了..谢谢老兄..在目标上你太傻了..谢谢老兄..我太傻了..谢谢老兄..在目标上你太傻了..B-)