50% OFF!!!

Booking.com

Friday, August 28, 2009

J2ME String Split method

Here is my code for splitting a string under Java - J2ME.
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;
}