Case insensitive String split() method

前端 未结 6 1611
北海茫月
北海茫月 2020-12-10 01:48

When I perform

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

I got two items in array as 23 and

6条回答
  •  盖世英雄少女心
    2020-12-10 02:33

    I personally prefer using

    String modified = Pattern.compile("x", Pattern.CASE_INSENSITIVE).matcher(stringContents).replaceAll(splitterValue);
    String[] parts = modified.split(splitterValue);
    

    In this way you can ensure any regex will work, as long as you have a unique splitter value

提交回复
热议问题