Java String Trim Left ltrimNewline(String s)

Here you can find the source of ltrimNewline(String s)

Description

Trims specified string from left and stop at \n character

License

Open Source License

Parameter

Parameter Description
s a parameter

Declaration

public static String ltrimNewline(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  ww  .  j a v a  2s  .co  m
     * Trims specified string from left and stop at <code>\n</code> character
     * 
     * @param s
     */
    public static String ltrimNewline(String s) {
        if (s == null) {
            return null;
        }

        int index = 0;
        int len = s.length();

        while (index < len && Character.isWhitespace(s.charAt(index))) {
            if (s.charAt(index) == '\n') {
                break;
            }
            index++;
        }
        if (index == 0) {
            return s;
        }
        return (index >= len) ? "" : s.substring(index);
    }
}

Related

  1. ltrim(String str)
  2. ltrim(String str, String charList)
  3. ltrim(String str, String defaultValue)
  4. ltrim(String text, char c)
  5. ltrimCount(final String input)
  6. ltrimZero(String inputString)