this is very helpfull for using a string array instead of string manipulation.
This is the best & fastest splitting method
Code:
public static String[] split(String p_text, String p_seperator)
{
Vector vecStrings = new Vector();
int index;
int prevIdx = 0;
while ((index = p_text.indexOf(p_seperator, prevIdx)) > -1)
{
vecStrings.addElement(p_text.substring(prevIdx, index));
prevIdx = index + 1;
}
vecStrings.addElement(p_text.substring(prevIdx));
String[] result = new String[vecStrings.size()];
vecStrings.copyInto(result);
return result;
}
Code is excellent. Working fine.Thanks for your solution.
ReplyDeleteThe line:
ReplyDeleteprevIdx = index + 1;
works only for a single-character separator. It should be replaced with:
prevIdx = index + p_seperator.length();