Here you can find the source of rightTrim(StringBuilder pStringBuilder)
Parameter | Description |
---|---|
pStringBuilder | The StringBuffer object to remove leading and trailing whitespace characters from. |
public static StringBuilder rightTrim(StringBuilder pStringBuilder)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww .j a v a 2 s . c om * Similar to the Perl chomp command. Removes all trailing * whitespace. * * @param pStringBuilder The StringBuffer object to remove leading and trailing whitespace * characters from. * @return StringBuilder the chomped string. */ public static StringBuilder rightTrim(StringBuilder pStringBuilder) { int endPos = pStringBuilder.length() - 1; while (endPos != -1 && Character.isWhitespace(pStringBuilder.charAt(endPos))) { pStringBuilder.deleteCharAt(endPos); } return pStringBuilder; } /** * Similar to the Perl chomp command. Removes all trailing * whitespace. * * @param pString The String object to remove leading and trailing whitespace * characters from. * @return String the chomped string. */ public static String rightTrim(String pString) { return rightTrim(new StringBuilder(pString)).toString(); } }