convert new line to <br> - Java java.lang

Java examples for java.lang:String New Line

Description

convert new line to <br>

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String input = "\nbon\n\n\n\n\n\k2s.com";
        System.out.println(nl2br(input));
    }// w  w  w.  jav  a2s.  c om

    public static String nl2br(String input) {
        if (input == null)
            return null;
        return input.replaceAll("\n", "<br>");
    }
}

Related Tutorials