I have the following input txt file: "Hamlet \r William Shakespeare" "Romeo and Juliet \r William Shakespeare" "For the whom the bell tolls \r Earnest Hemingway"
I load it into an array and when I output it I get:
Hamlet \r William Shakespeare.
Why is it not reading the carriage return character?
Thanks
答案 0 :(得分:0)
If you have \r
in a file, it won't be read as the character \r
(special return character), it will be read as 2 separate characters \
and r
.
You can fix this by replacing the string "\r" with the special charater \r
.
content = content.replacingOccurrences(of: "\\r", with: "\r")