lunedì 16 novembre 2009

String split to specified length


public static String[] slice(String str, int maxLength)
{
Pattern p = Pattern.compile(".{1," + maxLength + "}");
Matcher m = p.matcher(str);
List result = new ArrayList();
while (m.find())
{
result.add(m.group());
}
return result.toArray(new String[result.size()]);
}

in riferimento a: Java Programming - How do I split a string into chunks of a specified length? (visualizza su Google Sidewiki)

Nessun commento:

Posta un commento