Hi my problem is that i'm making a mobile app and i need to seperate the following string:




What is the easiest way to do this in J2ME ?

i had a look at the Ostermiller one but didnt understand it.

Thanks Chris

Re: J2ME StringTokenizer 80 80

How is that delimited? Is there anything between the sH or the r2?
Suppose the name is

Re: J2ME StringTokenizer 80 80

i've never used a tokeniser before so i dont know what delimited is. However there is a space between s and H and also between r and 2.

I get the string from a record store and need to tokenise it after its been retreived.

sorry if my description is a little vague i dont have much experience with record stores or tokenising



Re: J2ME StringTokenizer 80 80

OK, it looked like no spaces. With spaces its easy.
This is from the StringTokeniser documentation:

The following is one example of the use of the tokenizer. The code:

     StringTokenizer st = new StringTokenizer("this is a test");
     while (st.hasMoreTokens()) {

prints the following output:


end quote.

Assuming its the same in Java ME, that's pretty much all you need to know!

Uh-oh. Looks like StringTokenizer is deprecated in ME. The String class has a split method that splits things up OK. Look at that.

Re: J2ME StringTokenizer 80 80

Thanks for you help, i figured it out and used the split method heres my code:

private void showAllRecords()
        //gets entered ID 
        int recID = Integer.parseInt(textField6.getString());
            byte[] Details = new byte[frs.getRecordSize(recID)];
            // Gets record using entered ID
            Details = frs.getRecord(recID);
            // Calls split() and stores vextor returned by split()
            String[] splitStr = split( new String (Details));
            // Uses array index to store appropreate array value in textField
        catch (Exception e)

    // Split a string with symblo, return vecotr
    private String[] split(String original)
        Vector nodes = new Vector();
        String separator = ",";
        // Parse nodes into vector
        int index = original.indexOf(separator);
            nodes.addElement( original.substring(0, index) );
            original = original.substring(index+separator.length());
            index = original.indexOf(separator);
        // Get the last node
        nodes.addElement( original );
        // Create string array with segments of split string
        result = new String[nodes.size()];
        if( nodes.size()>0 )
            for(int loop=0; loop<nodes.size(); loop++)
            result[loop] = (String)nodes.elementAt(loop);
    return result;

Some of the comments may be wrong but code works.

Re: J2ME StringTokenizer 80 80

1. Post moved to Mobile development section
2. James not sure about deprecation of Tokenizer, as far I know it was never part of Microedition
3. Chris I think your problem is in the way of storing data in RecordStore. Since you are transforming your entries directly to byte array you have to go through string splitting. If you used DataInputStream and DataOutputStream you would make your life easier. You can use read/write in type oriented manner meaning use readBoolean(), readDouble(), writeFloat() writeUTF() etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.