How do I replace {a string inside Java
•
Java
Anyone can help me replace 'in the string in Java{‘
For example
String str = "abc{ad}"; str = str.replace("{","(");
But this seems impossible
Solution
{and (are meteacharacters in Java. You should escape them with a backslash. Instead of using regular expressions, string.replace uses [string. Replaceall] [1] or string.replacefirst instead
str = str.replaceAll("\\{","\\(");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码