Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I split strings in J2ME?

How do I split strings in J2ME in an effective way?

There is a StringTokenizer or String.split(String regex) in the standard edition (J2SE), but they are absent in the micro edition (J2ME, MIDP).

like image 214
Spoike Avatar asked Oct 14 '08 11:10

Spoike


People also ask

How do I split a string into multiple substrings?

split() The method split() splits a String into multiple Strings given the delimiter that separates them. The returned object is an array which contains the split Strings. We can also pass a limit to the number of elements in the returned array.

How do you split a string in white space?

You can split a String by whitespaces or tabs in Java by using the split() method of java. lang. String class. This method accepts a regular expression and you can pass a regex matching with whitespace to split the String where words are separated by spaces.

Is there a way to split string in Java?

The string split() method breaks a given string around matches of the given regular expression. After splitting against the given regular expression, this method returns a string array.


2 Answers

There are a few implementations of a StringTokenizer class for J2ME. This one by Ostermiller will most likely include the functionality you need

See also this page on Mobile Programming Pit Stop for some modifications and the following example:

String firstToken;
StringTokenizer tok;

tok = new StringTokenizer("some|random|data","|");
firstToken= tok.nextToken();
like image 95
Jonas Pegerfalk Avatar answered Oct 25 '22 23:10

Jonas Pegerfalk


There is no built in method to split strings. You have to write it on your own using String.indexOf() and String.substring(). Not hard.

like image 44
Guido Avatar answered Oct 25 '22 21:10

Guido