Java String Trim Right rtrim(String src, char ch, int nLen)

Here you can find the source of rtrim(String src, char ch, int nLen)

Description

rtrim

License

Open Source License

Parameter

Parameter Description
src a parameter
ch a parameter
nLen a parameter

Declaration

public static String rtrim(String src, char ch, int nLen) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  ww w .ja  v a 2  s.  co  m*/
     * 
     * 
     * @param src 
     * @param ch 
     * @param nLen 
     * @return
     */
    public static String rtrim(String src, char ch, int nLen) {
        if (src == null || src.length() <= nLen)
            return src;

        char[] czSrc = src.toCharArray();
        int i, j;
        int n = czSrc.length;
        for (i = n - 1; i >= nLen; i--) {
            if (czSrc[i] != ch)
                break;
        }

        char[] czRet = new char[i + 1];
        for (j = i; i >= 0; i--, j--)
            czRet[j] = czSrc[i];

        return new String(czRet);
    }
}

Related

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