Thursday, March 4, 2010

String manipulation, split string with specified delimeter and store into vector

public class StringManip {

public static Vector split(String str, final String delim, boolean discardEndData) {
Vector vComponents = new Vector();
int index = 0;

while (index < str.length()) {
int newIndex = str.indexOf(delim, index);
if (newIndex > 0) {
vComponents.addElement(str.substring(index, newIndex));
} else {
if (discardEndData == false) {
vComponents.addElement(str.substring(index));
}
break;
}

index = newIndex + delim.length();
}

return vComponents;
}

example :-
Vector v = StringManip.split("aaa,aaaa,aaa,aa" , ",", false);

2 comments:

  1. puppuleeeeeeeeeeeeeeeeeeeeeeee

    ReplyDelete
  2. Hi there, awesome site. I thought the topics you posted on were very interesting. I tried to add your RSS to my feed reader and it a few. take a look at it, hopefully I can add you and follow.




    J2ME Application Development

    ReplyDelete