Android String Trim 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 {
    /**//  ww w .  j  a v  a2 s  .  c  om
     * 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. rtrim(final String text)
  2. rtrim(final String text, String trimText)
  3. trimSuffix(final String text, final String suffix)
  4. trimPrefix(final String text, final String prefix)
  5. trimSpace(String oldString)
  6. trim(String s, char c)
  7. trim(String trimStr, String trimChars)
  8. trimEnd(String s, String extraChars)
  9. trimStart(String s, String extraChars)