I want to remove end-of-line characters from a comment body. Things I tried:
- comment.body.trim
- trim doesn't remove end-of-line characters for whatever reason.
- xmlEncode and other encodings
- did not seem to encode the end-of-line characters so I could remove them
- replaceAll(regex,string)
- the regex is applied line-by-line, so trailing end-of-line characters get processed, but not removed
Ultimately I decided to use indexOf to get the first instance of an "\r" character. But in order to effectively remove them, I had to make sure at least one was there. So I ended with this solution.
- comment.body.left(comment.body.concat("\r").indexOf("\r"))
This is obviously ugly. There should be a better way to remove end-of-line characters. Please help.