Reputation: 4434
I got a patternsyntax exception when i am trying to do a String.ReplaceAll.
Below is my String
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?
What i was trying to do:
junitReportString.replaceAll("?", "\n");
The above code fetched me the below exception:
java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0
Then i tried again with the below code:
junitReportString.replaceAll("\\?", "\n");
The above code fetched me the same String that i mentioned above.
My Complete Code:
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);
What is wrong with my code. Any guidance much appreciated.
Upvotes: 0
Views: 179
Reputation: 23002
#replaceAll
does not change the actual String
it just returns new String
which contains the changes.
junitReportString=junitReportString.replaceAll("\\?", "\n");
//Now you have changed String
Upvotes: 3