Hello,
You can try the following code
Code:
Public static String[] split(String in, String reg, boolean incsep) {
/ / We create a matcher that will search all partitions:
Matcher m = Pattern.compiles(reg).matcher(in);
/ / List of 'words' to return:
List <String> mtlst = new ArrayList <String>();
/ / Index out of words to be cut:
int index = 0;
/ / It searches for each separator:
while(m.find()) {
/ / We cut the string before the separator found:
mtlst.add( in.substring(index, m.home()) );
if (incsep) {
/ / It returns the separator:
mtlst.add( m.group() );
}
/ / We move the index after the separator
index = m.end();
}
if (Index ==0) {
/ / Special case: no separator found
/ / It returns the entire string:
return new String[] {in};
}
if (index <in.length()) {
/ / We add the end of the chain (last word)
mtlst.add( in.substring(Index) );
}
return mtlst.toArray(new String[mtlst.size()]);
}
Bookmarks