Java String Trim Right rightTrimNewLineChars(String input)

Here you can find the source of rightTrimNewLineChars(String input)

Description

Removes the occurrences of the passed char in the end of the string.

License

Open Source License

Declaration

public static String rightTrimNewLineChars(String input) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (C) 2012-2013  Fabio Zadrozny and others
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from   ww  w  .jav a2  s .  co  m
 *     Fabio Zadrozny <fabiofz@gmail.com>    - initial API and implementation
 *     Jonah Graham <jonah@kichwacoders.com> - ongoing maintenance
 ******************************************************************************/

public class Main {
    /**
     * Removes the occurrences of the passed char in the end of the string.
     */
    public static String rightTrimNewLineChars(String input) {
        int len = input.length();
        int st = 0;
        int off = 0;
        char c;
        while ((st < len)
                && ((c = input.charAt(off + len - 1)) == '\r' || c == '\n')) {
            len--;
        }
        return input.substring(0, len);
    }
}

Related

  1. rightTrim(String str)
  2. rightTrim(String string)
  3. rightTrim(String value)
  4. rightTrim(String[] values)
  5. rightTrim(StringBuilder pStringBuilder)
  6. rightTrimSize(String s)
  7. rightTrimSlashes(String s)
  8. rightTrimString(String originalString)
  9. rtrim(final String input)