Java String Trim Right rtrim(String s)

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

Description

Remove all trailing blanks.

License

Open Source License

Parameter

Parameter Description
s the string to be processed

Return

the result of the processing

Declaration

public static String rtrim(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww . j  a  va 2  s.  c o  m
     * Remove all trailing blanks.
     * @param s the string to be processed
     * @return the result of the processing
     */
    public static String rtrim(String s) {
        int index = s.length() - 1;

        while (index >= 0 && isSpace(s.charAt(index)))
            index--;

        return s.substring(0, index + 1);
    }

    /**
     * Check whether a character is a blank.
     * @param c the character to be checked
     * @return the result of the test
     */
    public static boolean isSpace(char c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t';
    }
}

Related

  1. rTrim(String orgStr, String delimiter)
  2. rtrim(String orig)
  3. rtrim(String pString)
  4. rtrim(String s)
  5. rtrim(String s)
  6. rTrim(String s)
  7. rtrim(String s)
  8. rtrim(String s)
  9. rtrim(String s)