Replace carriage returns and line feeds in out.println?

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2012-08-30T21:34:34Z Indexed on 2012/08/30 21:38 UTC
Read the original article Hit count: 162

Filed under:
|
|
|

I am a novice coder and I am using the following code to outprint a set of Image keywords and input a "|" between them.

<% Set allKeywords = new HashSet();
for (AlbumObject ao : currentObjects) {
XmpManager mgr = ao.getXmpManager();
if (mgr != null) {
allKeywords.addAll(mgr.getKeywordSet());    
  }
}
//get the Iterator
Iterator itr = allKeywords.iterator();
while(itr.hasNext()){
  String str = itr.next();
out.println(str +"|");   
} %>

I want the output to be like this:

red|blue|green|yellow

but it prints out:

red|
blue|
green|
yellow

which breaks my code. I've tried this:

str.replaceAll("\n", "");  
str.replaceAll("\r", ""); 

and

str.replaceAll("(?:\\n|\\r)", ""); 

No luck. I'd really appreciate some help!

© Stack Overflow or respective owner

Related posts about java

Related posts about string