Replace carriage returns and line feeds in out.println?
- by Mike
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!