Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I perform

String test="23x34 ";
String[] array=test.split("x"); //splitting using simple letter

I got two items in array as 23 and 34

but when I did

String test="23x34 ";
String[] array=test.split("X"); //splitting using capitalletter

I got one item in array 23x34

So is there any way I can use the split method as case insensitive or whether there is any other method that can help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
109 views
Welcome To Ask or Share your Answers For Others

1 Answer

split uses, as the documentation suggests, a regexp. a regexp for your example would be :

"[xX]"

Also, the (?i) flag toggles case insensitivty. Therefore, the following is also correct :

"(?i)x"

In this case, x can be any litteral properly escaped.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...