public static String[] splitBySeparator(String source, String separator) { int startIndex = 0; int endIndex = source.indexOf(separator); Vector vector = new Vector(); for (; endIndex >= startIndex; endIndex = source.indexOf(separator, startIndex)) { vector.add(source.substring(startIndex, endIndex)); startIndex = endIndex + separator.length(); } vector.add(source.substring(startIndex)); String returnValue[] = new String[vector.size()]; vector.copyInto(returnValue); return returnValue; }
public static String replaceAll(String src, String tarStr, String repStr) { int srcPos = 0; int tarPos = 0; StringBuffer result = new StringBuffer(25); while ((tarPos = src.indexOf(tarStr, srcPos)) >= 0) { result.append(src.substring(srcPos, tarPos)); result.append(repStr); srcPos = tarPos + tarStr.length(); } result.append(src.substring(srcPos)); String finalString = result.toString(); return finalString; }