/** * 扩展split方法 * 支持分割字符为一个数组,遇到数组中任意一个字符就分割 * 分割数组长度固定为2,只分割第一个出现的字符 * * @param charList * @param inputStr * @return */ private String[] expandSplit(List<Character> charList, String inputStr) { inputStr = inputStr.trim(); String[] strArray = new String[2]; StringBuilder stringBuilderBefore = new StringBuilder(); StringBuilder stringBuilderAfter = new StringBuilder(); int flag = 0; for (int index = 0; index < inputStr.length(); index++) { char singleChar = inputStr.charAt(index); if (flag == 0) { if (charList.contains(singleChar)) { flag = 1; } else { stringBuilderBefore.append(singleChar); } } else { stringBuilderAfter.append(singleChar); } } if (flag == 0) { strArray = new String[1]; strArray[0] = inputStr; return strArray; } strArray[0] = stringBuilderBefore.toString(); strArray[1] = stringBuilderAfter.toString(); return strArray; }
扩展split方法
最新推荐文章于 2024-06-19 13:34:05 发布