Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Replaces common newline characters like \n, \r, \r\n to the HTML line
     * break tag <br>.
     *
     * @param text the text to substitute.
     * @return the substituted text.
     */
    public static String htmlNewline(String text) {
        if (text == null || text.trim().isEmpty()) {
            return null;
        }

        return text.replaceAll("(\n|\r|\r\n)", "<br>");
    }
}