Title says it all. Here is some example code.
String test = '\n\n\n\n'; // All New Line characters System.debug( String.isBlank(test) ); // Returns true System.debug( String.isEmpty(test) ); // Returns false System.debug( test ); // Yields several empty lines in the debug output. test = test.stripHtmlTags(); System.debug( String.isBlank(test) ); // Returns true System.debug( String.isEmpty(test) ); // Returns true System.debug( test ); // Yields no empty lines in the debug output
So I have a String which may or may not have HTML tags. I want to remove the HTML tags and translate
<br> to new lines
\n, which stripHtmlTags does fine.
My problem is that I may not always have HTML in my string, and when I do not have HTML I still want to keep my formatting.
stripHtmlTags also removed carriage return
\r and tab space
\t and possibly others I didn't check.
This is the official response from Salesforce on the issue.
stripHtmlTags() is WAD and they are going to update the documentation to reflect the fact that it removes white-space characters as well as HTML tags.
As per update from the team, we have revisited the implementation of the method, we have created a Doc Bug to make note of this in our documentation. The whitespace characters in the string get stripped.
So, a Doc Bug has been logged for this to be included that whitespace kind of characters is not preserved when using this method.