| 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
|
 |
 |
|
|
subject: Removing or replacing a enter key chararcter from a string??
|
|
|