开发者

How to split a string with the character "[" using split() in java

开发者 https://www.devze.com 2023-04-12 14:32 出处:网络
I am not able to give 开发者_开发技巧\"[\" directly as it considers it as char set. If i try giving \"[\"

I am not able to give 开发者_开发技巧"[" directly as it considers it as char set. If i try giving "[" , i get a error saying escape sequence is not possible for "[".


Escape it with a double backslash:

\\[

This is needed to stop the regex engine treating the [ as the start of a character class.

The first backslash is needed since the \\[ is part of a string literal; only the second backslash will make it to the regex engine. In other words, the regex engine will see the above as \[.


org.apache.commons.lang.StringUtils.split( src, '[' )

Done. Why are you wasting time on this?

0

精彩评论

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