views:

353

answers:

1

In j2me ,i have editfield which takes its input ,in it we can enter 3 digits

when i enter first and third ,leaving 2nd digit empty ,

how to remove empty digit thanks

+1  A: 

You can create a replaceAll method like this:

public static String replaceAll(String text, String searchString, String replacementString) {
     StringBuffer sBuffer = new StringBuffer();
     int pos = 0;
     while ((pos = text.indexOf(searchString)) != -1) {
      sBuffer.append(text.substring(0, pos) + replacementString);
      text = text.substring(pos + searchString.length());
     }
     sBuffer.append(text);
     return sBuffer.toString();
    }

Then you can call it this way:

text = replaceAll(text, " ", "");
Daniel Moura
Awesome, let's reimplement String.replaceAll from scratch.
Trejkaz
http://java.sun.com/javame/reference/apis/jsr139/java/lang/String.html See the api, there is no String.replaceAll.
Daniel Moura