-
Ignore Symbol
Hello everyone,
Alright, this is my 2nd day programming. I have a program where the user types a double into an input box. I'm telling the user to type a percent. How can I make it, so that if the user types
"15" OR "15%"
That they both equal 15?
In other words, eliminate the "%"?
Thanks!
-
this:
Code:
string.replaceAll("\\%", "");
will return string with all percents removed. i.e.,
Code:
public class Fubar
{
public static void main(String[] args)
{
String string1 = "15";
String string2 = "15%";
System.out.println(stripPercent(string1));
System.out.println(stripPercent(string2));
int int1 = Integer.parseInt(stripPercent(string1));
int int2 = Integer.parseInt(stripPercent(string2));
System.out.println(int1 + int2);
}
private static String stripPercent(String string)
{
return string.replaceAll("\\%", "");
}
}
-
That worked great! Thank you so much!!!