Here you can find the source of toHtmlString(String input)
public static String toHtmlString(String input)
//package com.java2s; //License from project: Apache License public class Main { public static String toHtmlString(String input) { if ((input == null) || (input.trim().length() == 0)) { return input; }/*from w ww .j av a 2 s .co m*/ StringBuffer result = new StringBuffer(); char tmp; char lstchar = ' '; for (int i = 0; i < input.length(); i++) { tmp = input.charAt(i); if (((int) tmp) == 13) { result.append("<br>"); lstchar = tmp; } else if (((int) tmp) == 10) { if (((int) lstchar) == 13) { result.append(""); } else { result.append("<br>"); } } else { result.append(input.charAt(i)); } } return result.toString(); } }