Here you can find the source of rightTrim(String str)
Parameter | Description |
---|---|
str | String to treat |
public static String rightTrim(String str)
//package com.java2s; /*/*w w w .j a v a 2s.com*/ * File: MiscUtil.java * Copyright (c) 2004-2007 Peter Kliem (Peter.Kliem@jaret.de) * A commercial license is available, see http://www.jaret.de. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html */ public class Main { /** * Removes trailing whitespaces. * * @param str String to treat * @return str without trailing whitespaces */ public static String rightTrim(String str) { if (str.length() == 0) { return str; } int i = str.length() - 1; while (i >= 0) { char c = str.charAt(i); if (Character.isWhitespace(c)) { i--; } else { break; } } return str.substring(0, i + 1); } }