Hi,
I am new to java. I want to know how you guys remove the letters in a string?
Can someone please help me out?
Hi,
I am new to java. I want to know how you guys remove the letters in a string?
Can someone please help me out?
Calling following method with any String will return a numbers-only string.
Hope this helps.Code:public static String getOnlyNumerics(String str) { if (str == null) { return null; } StringBuffer strBuff = new StringBuffer(); char c; for (int i = 0; i < str.length() ; i++) { c = str.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } } return strBuff.toString(); }
Try this:
Code:for (int j = 0; j < keyword.length(); j++) { letter = keyword.charAt(j); for (int i = 0; i < alphabet.length(); i ++) { if (alphabet.charAt(i) != letter) { r += alphabet.charAt(i); } } }
To extract or remove a String.
Code:public class Sample1 { public static void main(String[] args) { String name = "chickens"; String extracted1, extracted2, extracted3; extracted1 = name.substring(1); extracted2 = name.substring(2); extracted3 = name.substring(3); System.out.println(extracted1); System.out.println(extracted2); System.out.println(extracted3); } }
Bookmarks