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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i remove newline characters and tabs

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
I am usign jdk 1.5 I hear removAll shoudld do the trick.

I have a string buffer of xml
Code:
buf.append("NAME |\n");
        buf.append("ID |\n");
        buf.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); 
        buf.append("<xml>\n"); 
        buf.append("</xml>\n");
if i do ...
Code:
        String s = buf.toString();
        s.replaceAll("\n","");
        s.replaceAll("\t","");
the newline characters, tabs do not dissapear
Code:
        String s = buf.toString();
        s.replaceAll("\\n","");
        s.replaceAll("\\t","");
that does not work either, according to the debugger
 
From the javadocs:
public String replaceAll(String regex,
String replacement)

Replaces each substring of this string that matches the given regular expression with the given replacement.
...
Returns:
The resulting String
[\quote]
Special concentration should be spend on the term 'returns', remembering Strings are immutable.

seeking a job as java-programmer in Berlin:
 
ahhh,
so
s = s.replaceAll("\\n","");
s = s.replaceAll("\\t","");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top