0

Basically my questions is how can i remove the digits from a string that is being inputted Thanks for helping me as well

Example:

Input

700N

Output:

N

  • Naive approach: loop over every character of the string. If it is not a number, add it to the result string. – domsson May 13 '20 at 05:42
  • Or maybe this? [Java: removing numeric values from string](https://stackoverflow.com/questions/17516049/java-removing-numeric-values-from-string) – domsson May 13 '20 at 05:45

3 Answers3

2

Use String.replaceAll() method:

str.replaceAll("[0123456789]","");
TaQuangTu
  • 2,155
  • 2
  • 16
  • 30
2

You can use replaceAll

    String st1 = "700N";
    st1 = st1.replaceAll("\\d+", "");
    System.out.println(st1);

output

N
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64
2

The best way I could come up with :

String input ="700N";
String output= input.replaceAll("\\d","");

The regex \\d means digit.

Omid.N
  • 824
  • 9
  • 19