To replace any character from a String, we generally use replaceAll() method of String.
Below is the example
String Str = new String("Hello + world +");
System.out.print("Output Value :" );
System.out.println(Str.replaceAll("[+]",
"" ));
O/P:
Output Value :Hello world
But It doesnt work if we want to replace square bracket from a String.
Here is the solution.
String str = "[[Hello world]";
str = str.replaceAll("\\[", "").replaceAll("\\]","");
System.out.println("Output Value :"+str );
O/P:
Output Value :Hello world
0 Comment(s)