开发者

Replace [] with () in a String

How can I change a String like this:

[a,b,c]

to this:

(a,b,c)
开发者_开发百科

I want to use Java's regular expressions.


If your problem is just these parentheses, something like this could suffice:

s.replaceAll("\\[", "(").replaceAll("\\]", ")")


Actualy you can do this by invoking replaceAll once

"[a, b, c]".replaceAll("\\[([^\\]]+)\\]", "($1)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜