0

I am trying to take string in a textbox and then split the text from the text box and display it on another form but i am not able to achieve it as everytime i put split function it shows me an error Here's the code

if (c == next) {
  String str = tb.getString();
  String[] st = str.split(":|;")
  System.out.println(st);

  f1.append(str);

  display.setCurrent(f1);
}
4
  • Can you share the error? Commented Mar 10, 2016 at 14:22
  • everytime i put split function it shows me an error which error? please paste the stacktrace in the question Commented Mar 10, 2016 at 14:22
  • 3
    I'm assuming it's not simply the missing ; on the end of the line...? Commented Mar 10, 2016 at 14:25
  • You aren't printing the array correctly. Try System.out.println(Arrays.toString(st)); Commented Mar 10, 2016 at 14:35

3 Answers 3

2

Split method is not supported in J2ME.

Sign up to request clarification or add additional context in comments.

Comments

1

you have missed the ;

if (c == next) {
  String str = tb.getString();
  String[] st = str.split(":|;");
  System.out.println(st);

  f1.append(str);

  display.setCurrent(f1);
}

Comments

0
/**
 * Splits a string into multiple strings
 *
 * @param separator Separator char
 * @param source_string Source string
 * @return Array of strings
 *
 * source :
 * http://www.particle.kth.se/~lindsey/JavaCourse/Book/Code/P3/Chapter24/SNAP/Worker.java
 */
public static String[] split(char separator, String source_string) {

    // First get rid of whitespace at start and end of the string
    String string = source_string.trim();
    // If string contains no tokens, return a zero length array.
    if (string.length() == 0) {
        return (new String[0]);
    }

    // Use a Vector to collect the unknown number of tokens.
    Vector token_vector = new Vector();
    String token;
    int index_a = 0;
    int index_b;

    // Then scan through the string for the tokens.
    while (true) {
        index_b = string.indexOf(separator, index_a);
        if (index_b == -1) {
            token = string.substring(index_a);
            token_vector.addElement(token);
            break;
        }
        token = string.substring(index_a, index_b);
        token_vector.addElement(token);
        index_a = index_b + 1;
    }

    return toStringArray(token_vector);

} // split

/**
 * Convert a vector to an array of string
 *
 * @param vector Vector of string
 * @return Array of string
 */
public static String[] toStringArray(Vector vector) {
    String[] strArray = new String[vector.size()];
    for (int i = 0; i < strArray.length; i++) {
        strArray[i] = (String) (vector.elementAt(i));
    }
    return strArray;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.