When I retrieve lyrics from this page: here, the newlines disappear. I retrieve the xml in single String, and for simpleness for this question I use substring to subtract the lyrics. When I print each character using the following code, no newlines are visible.
if (response.contains("lyrics_body")) {
lyrics = response.substring(response.indexOf("<lyrics_body>") + 13, response.indexOf("</lyrics_body>"));
StringReader sr = new StringReader(lyrics);
int l;
try {
while ((l = sr.read()) != -1) {
System.out.println(":" + l);
}
} catch (Exception ex) {
}
}
Part of the output:
85 U
104 h
110 n
32
116 t
105 i
115 s
115 s
32
117 u
104 h
110 n
32
116 t
105 i
115 s
115 s
32
117 u
104 h
110 n
32
116 t
105 i
115 s
115 s
32
98 b
97 a
98 b
121 y
68 d
111 o
103 g
32
119 w
105 i
108 l
108 l
.
.
I’ve added the individual chars behind the numbers for clarity, and obviously between ‘baby’ and ‘dog’ there should be a newline.
How can I parse this newline?
I’ve used this source from somewhere:
Obviously, the part where it says “I’ve just added this line” was the problem, thanks Jon for making me look in this code!