keep only alphabet characters

后端 未结 5 1932
离开以前
离开以前 2021-02-06 22:34

What method should I follow in java to produce

\"WordWord\"

from

\"Word#$#$% Word 1234\"
5条回答
  •  长情又很酷
    2021-02-06 23:18

    You can use Character.isLetter(char c) in Character class like this

     String s = "Word#$#$% Word 1234";
     StringBuffer r = new StringBuffer();
     for (int k = 0; k < s.length(); k++) {
         if(Character.isLetter(s.charAt(k)))
            r.append(s.charAt(k));     
     }
     System.out.println("Result " + r.toString());
    

提交回复
热议问题