Sagar Samtani
Sagar Samtani

Reputation: 203

Removing newlines and returns from HTML using Java

I am parsing HTML content using Java, and am trying to remove the \r\n from \r\n26.11.2012. I have used the following code in my program to try and remove the \r\n, but it does not seem to work.

attribute = attribute.replaceAll("(\\r|\\n|\\t)", "");

How can this code be adjusted to convert \r\n26.11.2012 to 26.11.2012 ?

Upvotes: 3

Views: 52

Answers (1)

slipperyseal
slipperyseal

Reputation: 2778

        TestCase.assertEquals("26.11.2012", "\r\n26.11.2012".replaceAll("(\\r|\\n|\\t)", ""));

Your code actually works. This test case passes. Perhaps the input isn't what you expect or the attribute value is being processed on the way out and this has added the characters.

Upvotes: 1

Related Questions