Here you can find the source of rtrim(String pString)
Parameter | Description |
---|---|
pString | the string to trim |
public static String rtrim(String pString)
//package com.java2s; public class Main { /**/*from w w w. j a v a 2s .c om*/ * Trims the argument string for whitespace on the right side only. * * @param pString the string to trim * @return the string with no whitespace on the right, or {@code null} if * the string argument is {@code null}. * @see #ltrim * @see String#trim() */ public static String rtrim(String pString) { if ((pString == null) || (pString.length() == 0)) { return pString;// Null or empty string } for (int i = pString.length(); i > 0; i--) { if (!Character.isWhitespace(pString.charAt(i - 1))) { if (i == pString.length()) { return pString;// First char is not whitespace } else { return pString.substring(0, i);// Return before whitespace } } } // If all whitespace, return empty string return ""; } /** * Gets the first substring between the given string boundaries. * <p/> * * @param pSource The source string. * @param pBeginBoundaryString The string that marks the beginning. * @param pEndBoundaryString The string that marks the end. * @param pOffset The index to start searching in the source * string. If it is less than 0, the index will be set to 0. * @return the substring demarcated by the given string boundaries or null * if not both string boundaries are found. */ public static String substring(final String pSource, final String pBeginBoundaryString, final String pEndBoundaryString, final int pOffset) { // Check offset int offset = (pOffset < 0) ? 0 : pOffset; // Find the start index int startIndex = pSource.indexOf(pBeginBoundaryString, offset) + pBeginBoundaryString.length(); if (startIndex < 0) { return null; } // Find the end index int endIndex = pSource.indexOf(pEndBoundaryString, startIndex); if (endIndex < 0) { return null; } return pSource.substring(startIndex, endIndex); } }