In java ,i have editfield whcih takes its input ,in it we can enter 3 digits
when i enter first and third ,leaving 2 digit empty ,how to remove empty digit thanks
In java ,i have editfield whcih takes its input ,in it we can enter 3 digits
when i enter first and third ,leaving 2 digit empty ,how to remove empty digit thanks
If you've got "X_Y
" ("_
" indicating a missing character) and you want "XY", then
String newString = entered.charAt(0) + entered.charAt(2)
is the simplest way. But that's only useful for this one particular case. Do you not want to handle missing beginning and end characters too ?
If you want to remove all white space internally in a String (which is what I think you're asking), then you want something like:
sText.replaceAll("\\s+", "")
Hope that helps.
Stripping spaces from a String (don't know if J2ME has StringBuilder so I'll just do ugly String concatenation):
String noSpaces = "";
for (int i=0; i<perhapsSpaces.length(); i++)
{
if (perhapsSpaces.charAt(i) != ' ')
noSpaces += perhapsSpaces.charAt(i);
}
For "better" space handling, perhaps Character.isWhitespace?