Java String Trim Right rtrim(final String text)

Here you can find the source of rtrim(final String text)

Description

rtrim

License

Apache License

Declaration

public static final String rtrim(final String text) 

Method Source Code

//package com.java2s;
/*//from w  w  w .  ja v  a 2s . co m
 * Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

public class Main {
    public static final String rtrim(final String text) {
        return rtrim(text, null);
    }

    public static final String rtrim(final String text, String trimText) {
        if (text == null) {
            return null;
        }
        if (trimText == null) {
            trimText = " ";
        }
        int pos = text.length() - 1;
        for (; pos >= 0; pos--) {
            if (trimText.indexOf(text.charAt(pos)) < 0) {
                break;
            }
        }
        return text.substring(0, pos + 1);
    }
}

Related

  1. rightTrimSlashes(String s)
  2. rightTrimString(String originalString)
  3. rtrim(final String input)
  4. rtrim(final String str)
  5. rtrim(final String str, final char filler)
  6. rTrim(final String value)
  7. rtrim(String input)
  8. rTrim(String orgStr, String delimiter)
  9. rtrim(String orig)