How can I delete the last digit entered. I have a button named "clear" and the code for the display is
display = " ";and it removes/clears the entire text. Now my problem is, how do I delete it one character at a time?
Thanks,
Haydee
display = " ";and it removes/clears the entire text. Now my problem is, how do I delete it one character at a time?
|
|
|
String var = "Entered Text.";
while(var.length() > 1) {
var = var.substring(0, var.length()-1);
System.out.println("Text: "+var);
}
Quote
public static void main(String[] args) {
long start = System.currentTimeMillis();
stringConcat();
System.out.println(System.currentTimeMillis() - start);
start = System.currentTimeMillis();
stringBuilder();
System.out.println(System.currentTimeMillis() - start);
}
private static void stringConcat() {
String s = "";
for (int i = 0; i < 100000; i++) {
s += "a";
}
}
private static void stringBuilder() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100000; i++) {
sb.append("a");
}
sb.toString();
}
public void removeLastDig()
{
display.trim(); // In case of spaces that could have come after the digits
display = display.substring(0, display.length()-1);
}
public void removeLastDig()
{
for(int i = display.length()-1; i >= 0; i--)
{
if(Character.isDigit(display.charAt(i)))
{
display = display.subSequence(0, i) + display.substring(i+1);
break;
}
}
}