Here you can find the source of unPadRight(String s, char c)
Parameter | Description |
---|---|
s | - original string |
c | - padding char |
public static String unPadRight(String s, char c)
//package com.java2s; public class Main { /**/*w ww. j a va2 s . c om*/ * Unpad from right. In case the string to be returned is empty, the result * is c * * @param s * - original string * @param c * - padding char * @return unPadded string. */ public static String unPadRight(String s, char c) { if ((s.trim().length() == 0) && (c == ' ')) return Character.toString(c); else if ((s.trim().length() == 0)) return s; String sTrim = s.trim(); int end = sTrim.length(); while ((0 < end) && (sTrim.charAt(end - 1) == c)) end--; return (0 < end) ? sTrim.substring(0, end) : sTrim.substring(0, 1); } }