Here you can find the source of htmlLineBreaks(String s)
Parameter | Description |
---|---|
s | the string to process. |
public static String htmlLineBreaks(String s)
//package com.java2s; public class Main { /**//from www . ja v a 2s . c o m * Convert newlines in the string into <br/> tags. * * @param s the string to process. * @return processed string. */ public static String htmlLineBreaks(String s) { if (s == null) { return ""; } StringBuilder out = new StringBuilder(); char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '\n') { out.append("<br />"); } else if (chars[i] == '\r') { if (i < chars.length - 1 && chars[i + 1] == '\n') { i++; } out.append("<br />"); } else { out.append(chars[i]); } } return out.toString(); } }