Bimp
Bimp

Reputation: 494

System.getProperty("line.separator") equivalent in j2me

I need to have a cross-platform newline reference to parse files, and I'm trying to find a way to do the equivalent of the usual

System.getProperty("line.separator");

but trying that in J2ME, I get a null String returned, so I'm guessing line.separator isn't included here. Are there any other direct ways to get a universal newline sequence in J2ME as string?

edit: clarified question a bit

Upvotes: 2

Views: 876

Answers (2)

Bimp
Bimp

Reputation: 494

Seems like I forgot to answer my question. I used a piece of code that allowed me to use "\r\n" as delimiter and actually considered \r and \n as well seperately:

public class Tokenizer {
   public static String[] tokenize(String str, String delimiter) {

       StringBuffer strtok = new StringBuffer();
       Vector buftok = new Vector();

       char[] ch = str.toCharArray();                       //convert to char array
       for (int i = 0; i < ch.length; i++) {

           if (delimiter.indexOf(ch[i]) != -1) {   //if i-th character is a delimiter               
               if (strtok.length() > 0) {
                   buftok.addElement(strtok.toString());
                   strtok.setLength(0);
               }
           } 
           else {
               strtok.append(ch[i]);
           }
       }

       if (strtok.length() > 0) {
           buftok.addElement(strtok.toString());
       }


       String[] splitArray = new String[buftok.size()];
       for (int i=0; i < splitArray.length; i++) {
           splitArray[i] = (String)buftok.elementAt(i);
       }
       buftok = null;

       return splitArray;
   }
}

Upvotes: 2

yoninja
yoninja

Reputation: 1962

I don't think "line.separator" is a system property of JME. Take a look at this documentation at SDN FAQ for MIDP developers: What are the defined J2ME system property names?

Why do you need to get the line separator anyway? What I know is that you can use "\n" in JME.

Upvotes: 1

Related Questions