Java String Trim Right rtrim(String str, String charList)

Here you can find the source of rtrim(String str, String charList)

Description

rtrim

License

Open Source License

Declaration

public static String rtrim(String str, String charList) 

Method Source Code

//package com.java2s;
/*/*  ww w. ja  va  2  s . c  o  m*/
 * -----LICENSE START-----
 * JSHManager - A Java-based tool for managing one's ScoreHero account.
 * Copyright (C) 2008 Tim Mullin
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * -----LICENSE END-----
*/

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

    public static String rtrim(String str, String charList) {
        int end = str.length() - 1;

        if (null == charList)
            for (int i = end; i >= 0; i--)
                if (Character.isWhitespace(str.charAt(i)))
                    end--;
                else
                    break;
        else
            for (int i = end; i >= 0; i--)
                if (charList.indexOf(str.charAt(i)) >= 0)
                    end--;
                else
                    break;

        return str.substring(0, end + 1);
    }
}

Related

  1. rTrim(String str)
  2. rtrim(String str)
  3. rtrim(String str)
  4. rtrim(String str)
  5. rtrim(String str)
  6. rtrim(String str, String defaultValue)
  7. rtrim(String str, String suffixs)
  8. rtrim(String string, String end)
  9. rtrim(String text, char c)