不区分大小写的String split()方法 [英] Case insensitive String split() method
本文介绍了不区分大小写的String split()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行时
String test="23x34 ";
String[] array=test.split("x"); //splitting using simple letter
我在数组中有两个项目为23和34
I got two items in array as 23 and 34
但是当我这么做时
String test="23x34 ";
String[] array=test.split("X"); //splitting using capitalletter
我在数组中有一个项目23x34
I got one item in array 23x34
那么有什么方法可以使用split方法作为不区分大小写或者是否有任何其他方法可以帮助?
So is there any way I can use the split method as case insensitive or whether there is any other method that can help?
推荐答案
在 [xX]
> split
Use regex pattern [xX]
in split
String x = "24X45";
String[] res = x.split("[xX]");
System.out.println(Arrays.toString(res));
这篇关于不区分大小写的String split()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文