Java String Trim Right rtrim(String s, char character)

Here you can find the source of rtrim(String s, char character)

Description

rtrim

License

Open Source License

Declaration

public static String rtrim(String s, char character) 

Method Source Code

//package com.java2s;
//License from project: MIT License 

public class Main {
    public static String rtrim(String s) {
        int i = s.length() - 1;
        while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
            i--;//  w ww . j  a va  2 s  . c  om
        }
        return i(s, 0, i + 1);
    }

    public static String rtrim(String s, char character) {
        int i = s.length() - 1;
        while (i >= 0 && s.charAt(i) == character) {
            i--;
        }
        return i(s, 0, i + 1);
    }

    public static String i(String s, int begin, int end) {
        if (s == null)
            return null;
        int len = s.length();
        if (begin < 0)
            begin += len;
        if (end < 0)
            end += len;
        if (begin < 0)
            begin = 0;
        if (end < 0)
            end = 0;
        if (begin >= len)
            return "";
        if (end > len)
            end = len;
        if (end <= begin)
            return "";
        return s.substring(begin, end);
    }

    public static String i(String s, int begin) {
        return i(s, begin, s.length());
    }
}

Related

  1. rtrim(String s)
  2. rtrim(String s)
  3. rtrim(String s)
  4. rTrim(String s)
  5. rtrim(String s, char character)
  6. rtrim(String s, Character c)
  7. rtrim(String source)
  8. rtrim(String source)
  9. rtrim(String src, char ch, int nLen)