Java String Trim Right rightTrim(String str)

Here you can find the source of rightTrim(String str)

Description

right Trim

License

Open Source License

Declaration

public static String rightTrim(String str) 

Method Source Code

//package com.java2s;

public class Main {
    public static String rightTrim(String str) {
        if (str == null)
            return str;
        int len = str.length();

        int count = 0;
        for (int i = len - 1; i >= 0; i--) {
            if (str.charAt(i) == ' ' || str.charAt(i) == '\n' || str.charAt(i) == '\r' || str.charAt(i) == '\t') {
                count++;//w  w w.  java  2s .c o  m
            } else {
                break;
            }
        }
        return str.substring(0, len - count);

    }
}

Related

  1. rightTrim(final String input, final char charToTrim)
  2. rightTrim(String input, char charToTrim)
  3. rightTrim(String s)
  4. rightTrim(String s, char c)
  5. rightTrim(String src)
  6. rightTrim(String str)
  7. rightTrim(String str)
  8. rightTrim(String string)
  9. rightTrim(String value)