Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 08-10-2009
Member
 
Join Date: Aug 2009
Posts: 10
Java - remove letters from string

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?
Reply With Quote
  #2  
Old 08-10-2009
Member
 
Join Date: Apr 2008
Posts: 55
Re: Java - remove letters from string

Calling following method with any String will return a numbers-only string.

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();
}
Hope this helps.
Reply With Quote
  #3  
Old 08-10-2009
Member
 
Join Date: May 2008
Posts: 41
Re: Java - remove letters from string

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);
                }
             }
    }
Reply With Quote
  #4  
Old 08-10-2009
Member
 
Join Date: Apr 2008
Posts: 32
Re: Java - remove letters from string

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);
    }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Java - remove letters from string"
Thread Thread Starter Forum Replies Last Post
Definition of a String in Java? cloud101 Software Development 5 28-07-2014 10:14 AM
how to remove certain characters from a String in java Baazigar Software Development 3 13-02-2010 08:02 PM
Java String test Aidan 12 Software Development 3 09-11-2009 02:22 PM
How to remove Drive letters using GPO Ayush Operating Systems 4 17-04-2009 01:22 PM
Changing small letters back to proper Capital letters in .doc rEDNESS TroubleShoot 98 2 04-03-2008 09:50 PM


All times are GMT +5.5. The time now is 02:18 AM.