2016-03-10 28 views
0

我想在文本框中的字符串,然后从文本框中拆分文本,并将其显示在另一个窗体上,但我无法实现它作为每次我把拆分功能它显示我一个错误 这里是你错过了在J2ME不支持;Java分裂功能不在j2me工作

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

    f1.append(str); 

    display.setCurrent(f1); 
} 
+0

您能分享错误? – gonzo

+0

'每当我把拆分功能它显示我一个错误'哪个错误?请在问题 – BackSlash

+3

中粘贴堆栈跟踪我假设它不是简单地在行末尾缺少';'......? –

回答

2

拆分方法的代码

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

    f1.append(str); 

    display.setCurrent(f1); 
} 
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; 
}