Splitting String/Text In J2ME

To split string/text in J2ME you can use these methods.
Include one of these method in your applications

public static String[] split (String a,String delimeter){
String c[]=new String[0];
String b=a;
while (true){
int i=b.indexOf(delimeter);
String d=b;
if (i>=0)
d=b.substring(0,i);
String e[]=new String[c.length+1];
for (int k=0;k
e[k]=c[k];
e[e.length-1]=d;
c=e;
b=b.substring(i+delimeter.length(),b.length());
if (b.length()<=0 || i<0 )
break;
} return c;
}
-----
/**
* A method for splitting a string in J2ME.
*
* @param splitStr The string to split.
* @param delimiter The characters to use as delimiters.
* @return An array of strings.
*/
public static String[] Split(String splitStr, String delimiter) {

StringBuffer token = new StringBuffer();
Vector tokens = new Vector();

// split
char[] chars = splitStr.toCharArray();
for (int i=0; i < chars.length; i++) {
if (delimiter.indexOf(chars[i]) != -1) {
// we bumbed into a delimiter
if (token.length() > 0) {
tokens.addElement(token.toString());
token.setLength(0);
}
} else {
token.append(chars[i]);
}
}
// don't forget the "tail"...
if (token.length() > 0) {
tokens.addElement(token.toString());
}

// convert the vector into an array
String[] splitArray = new String[tokens.size()];
for (int i=0; i < splitArray.length; i++) {
splitArray[i] = tokens.elementAt(i);
}
return splitArray;
}

8 comments:

  1. Haiy, i like ur blog so much. It's so useful.
    Do you have any sample program step-by-step to build email client in j2me?? I really need the tutorial to develop my thesis.
    Thanks before, mail me thrillelogy AT gmail DOT com

    ReplyDelete
  2. public static String[] stringToArray(String a,String delimeter)
    {
    String c[]=new String[0];
    String b=a;
    while (true)
    {
    int i=b.indexOf(delimeter);
    String d=b;
    if (i>=0)
    d=b.substring(0,i);
    String e[]=new String[c.length+1];
    for (int k=0;k<c.length;k++)
    e[k]=c[k];
    e[e.length-1]=d;
    c=e;
    b=b.substring(i+delimeter.length(),b.length());
    if (b.length()<=0 || i<0 )
    break;
    }
    return c;
    }

    fuente
    http://programmingtutorialz.blogspot.com/2010/01/j2me-string-split-method.html

    ReplyDelete
  3. hi can u help us in our research? what is the midlet codes for blocking messages? in detecting messages? our title in our research is to block bad text messages in mobile phone. could u help us?

    ReplyDelete
  4. splitArray[i] = tokens.elementAt(i);

    //This does not work in NetBeans. What is the alternative code for this.

    ReplyDelete
  5. Super bolg !!! congrats and thanks first.

    i'm new to j2me, know nothing about it.

    But i need to create an application to process and send the content of new unread sms to a weblink/website. its to be work automatically when a sms is received.

    Can you pls help me, it will be a great help for me...

    ReplyDelete
  6. @EL-EL said...

    ur code is

    splitArray[i] = tokens.elementAt(i).toString();

    ReplyDelete
  7. Hey buddy i need your help to create side menu bar for my mobile application......can you please help me...with coding.....

    ReplyDelete
  8. Do you mostly serve as an author just for this website or you do that for any other Internet or offline portals?

    ReplyDelete

 

Design by Blogger Buster | Distributed by Blogging Tips