I'm writing a text to HTML converter. I'm looking for a simple way to wrap each line of text (which ends with carriage return) with
<p>.....text.....</p>
Can you suggest some String replacement/regular expression that will work in Java ?
Thanks
String txtFileContent = ....;
String htmlContent = "<p>" + txtFileContent.replaceAll("\\n","</p>\\n<p>") + "</p>";
Assuming,
Hope this help
Try using StringEscapeUtils.escapeHtml
and then adding the tags you want at the beginning end.
String escapeHTML = StringEscapeUtils.escapeHtml(inputStr);
String output = "<p>"+escapeHTML+"</p>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.