Java String Trim Right rightTrimSize(String s)

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

Description

Returns the size of substring that does not contain any trailing spaces

License

Open Source License

Parameter

Parameter Description
s the string

Return

trimmed size

Declaration

public static int rightTrimSize(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w w  .  j a v  a2 s  . co m*/
     * Returns the size of substring that does not contain any trailing spaces
     * @param s the string
     * @return trimmed size
     */
    public static int rightTrimSize(String s) {

        int i = s.length();

        while (i > 0) {
            i--;

            if (s.charAt(i) != ' ') {
                return i + 1;
            }
        }

        return 0;
    }
}

Related

  1. rightTrim(String string)
  2. rightTrim(String value)
  3. rightTrim(String[] values)
  4. rightTrim(StringBuilder pStringBuilder)
  5. rightTrimNewLineChars(String input)
  6. rightTrimSlashes(String s)
  7. rightTrimString(String originalString)
  8. rtrim(final String input)
  9. rtrim(final String str)