aspose file tools
The moose likes Java in General and the fly likes Removing or replacing a enter key chararcter from a string?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Removing or replacing a enter key chararcter from a string??" Watch "Removing or replacing a enter key chararcter from a string??" New topic
Author

Removing or replacing a enter key chararcter from a string??

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi,

In my string i have some enter key characters.
I want to remove that or replace with some thing which can display that data in one line.

So how can i do this??


Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
Originally posted by Jignesh Gohel:
Hi,

In my string i have some enter key characters.
I want to remove that or replace with some thing which can display that data in one line.

So how can i do this??


The short answer is that you can't.

Strings are immutable, so you can't change their contents.

You can call methods on the String object that produce the result you want and then rearrange your String reference to point to the output.
Manhar Puri
Ranch Hand

Joined: Aug 23, 2005
Posts: 41
Enter key could be a character sequence of \n\r or just \n.

So first obtain the index of the character sequence i.e. \n\r or \n, using the indexOf() method on your string. Then create a string buffer

StringBuffer sb = new StringBuffer(String str);

After this use the delete function on the string ubffer to delete the character sequence and the convert this back to a String using the toString() method on the string buffer.

-Manhar.
Kevin Huang
Greenhorn

Joined: Mar 27, 2004
Posts: 13
use String's replace(char oldChar, char newChar) method to create the new String, if you are going to replace it by a char.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1295
Or



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing or replacing a enter key chararcter from a string??
 
Similar Threads
regarding multiline parameter passing through query string
How can a TextField get focus?
input
how to use tab key to on focus and 'Enter' key to select
textarea tag - Entering string problem