My problem is: I want to enter a number and my method should remove symbols like "+","/","-","." with the help of regex (pattern & matcher). My method looks like this:
"String eingabe" is the entered number:
String bindestrich = "-";
String plus = "+";
String slash = "/";
String punkt = ".";
String leer = "";
Pattern bindestrichP = Pattern.compile(bindestrich);
Matcher matchBindestrich = bindestrichP.matcher(eingabe);
eingabe = matchBindestrich.replaceAll(leer);
Pattern plusP = Pattern.compile(plus);
Matcher matchPlus = plusP.matcher(eingabe);
eingabe = matchPlus.replaceAll(leer);
Pattern slashP = Pattern.compile(slash);
Matcher matchSlash = slashP.matcher(eingabe);
eingabe = matchSlash.replaceAll(leer);
Pattern punktP = Pattern.compile(punkt);
Matcher matchPunkt = punktP.matcher(eingabe);
eingabe = matchPunkt.replaceAll(leer);
However it throws a PatternSyntaxException already at the Pattern-making point. What do I do wrong? Is there any simpler method to remove exact these symbols?
Aucun commentaire:
Enregistrer un commentaire