Here you can find the source of splitNotRegex(String str, String separatorChars)
Parameter | Description |
---|---|
str | a parameter |
separatorChars | a parameter |
public static String[] splitNotRegex(String str, String separatorChars)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.util.ArrayList; public class Main { public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final String EMPTY = ""; /**/* ww w . j a v a2 s. c o m*/ * replace the method : String.split(String regex) * * @param str * @param separatorChars * @return */ public static String[] splitNotRegex(String str, String separatorChars) { if (str == null) { return null; } int len = str.length(); if (len == 0) { return EMPTY_STRING_ARRAY; } int separatorLength = separatorChars.length(); ArrayList<String> substrings = new ArrayList<String>(); int beg = 0; int end = 0; while (end < len) { end = str.indexOf(separatorChars, beg); if (end > -1) { if (end > beg) { substrings.add(str.substring(beg, end)); beg = end + separatorLength; } else { substrings.add(EMPTY); beg = end + separatorLength; } } else { substrings.add(str.substring(beg)); end = len; } } int resultSize = substrings.size(); String[] result = substrings.toArray(new String[resultSize]); while (resultSize > 0 && substrings.get(resultSize - 1).equals("")) { resultSize--; // Setting data to null for empty string in last columns to keep original behavior result[resultSize] = null; } return result; } }