Siracuse
Siracuse

Reputation: 551

Is there a method in Java that allows me to replace all HTML special characters into their encoded equivelant?

I have a textfile which my Java program is modifying and putting into an HTML file for display.

However, this textfile contains lots of HTML unsafe characters such as "<" and the ">" which would need to be encoded into & gt; (sans space) and & lt;.

Is there some library method I can use to sanatize my text document to replace all these HTML special characters with their safe encoded equivelants?

Upvotes: 1

Views: 370

Answers (2)

phill
phill

Reputation: 486

If you want to build your own, it is fairly easy using the String replace method, you just need a list of targets and replacements, and bam, you're done.

replace(CharSequence target, CharSequence replacement)

Upvotes: 0

Ben
Ben

Reputation: 16533

Check out escapeHtml

Upvotes: 1

Related Questions