trim Line Separator from a string - Java java.lang

Java examples for java.lang:String Trim

Description

trim Line Separator from a string

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String txt = "java2s.com\n";
        System.out.println(trimLineSeparator(txt));
    }/*from  www .j  av  a 2  s .  com*/

    private static final String separator = "\n";

    public static String trimLineSeparator(String txt) {
        return txt.substring(0, txt.length() - separator.length());
    }
}

Related Tutorials