Java: removing numeric values from string

前端 未结 7 1840
心在旅途
心在旅途 2020-12-01 18:03

I have suceeded with the help of this community in removing numeric values from user input, however, my code below will only retrieve the alpha characters before the numeric

相关标签:
7条回答
  • 2020-12-01 18:52

    How to remove numeric values from a string:

    to do this it will be enough

    str.replaceAll("[^A-Za-z]","");
    

    but what if your string contain characters like:

    String str = "stackoverflow elenasys +34668555555 # Пивоварова Пивоварова հայեր հայեր አማሪኮ     አማሪኮ kiểm tra kiểmtra ตรวจสอบ ตรวจสอบ التحقق من التحقق من";
    

    most of the characters will be removed too, so this is a better option:

    str = str.replaceAll("[\\d.]", "");
    

    to remove all numeric values and get as result:

    stackoverflow elenasys + # Пивоварова Пивоварова հայեր հայեր አማሪኮ     አማሪኮ kiểm tra kiểmtra ตรวจสอบ ตรวจสอบ التحقق من التحقق من
    
    0 讨论(0)
提交回复
热议问题