Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove characters

Status
Not open for further replies.

DB2Problem

Programmer
Oct 17, 2002
53
US
Hi All.

I want to remove some extra character from the String..

String remove_me = Rem 33, 9999

There is a blank space afer Rem and after,

I want to remove , and blank spaces and make this as

String removed = Rem339999

Please give your feedback

Thanks
 
Here is one way to do that:

Code:
import java.util.*;

public class ReplaceText
{
	public static void main(String[] args) throws Exception
	{
		//The string that you want to parse
		String inputLine = "Rem 33, 9999";

		//I'm using a string buffer because I will break up the inputLine into tokens
		//and append it to the current string.
		StringBuffer parsedString = new StringBuffer();

		//Using the StringTokenizer class, the class will break the input
		//string into tokens where it finds a "," or white space
		StringTokenizer st = new StringTokenizer (inputLine, ", ");

		while (st.hasMoreTokens())
		{
			parsedString.append(st.nextToken());
		}

		//The output will look like: Rem339999
		System.out.println("The New String is " + parsedString);
	}
}

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top