Here you can find the source of rtrim(String text, char c)
Parameter | Description |
---|---|
text | a parameter |
c | a parameter |
public static String rtrim(String text, char c)
//package com.java2s; //License from project: Apache License public class Main { private static final String EMPTY = ""; /**//from www .j a v a2 s.co m * @param text * @param c * @return String */ public static String rtrim(String text, char c) { if (text == null) { return EMPTY; } int i = 0; int j = text.length(); while ((i < j) && (text.charAt(j - 1) == c)) { j--; } return (j < text.length()) ? text.substring(i, j) : text; } /** * @param source * @param length * @param padding * @return String */ public static String substring(String source, int length, String padding) { if (source == null) { return ""; } String s = source.trim(); char c; int size = 0; int count = s.length(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < s.length(); i++) { c = s.charAt(i); if (c >= 0x0080) { size += 2; count++; } else { size++; } if (size > length) { if (c >= 0x4e00) { size -= 2; } else { size--; } break; } buffer.append(c); } if (size < count && padding != null) { buffer.append(padding); } return buffer.toString(); } /** * @param text * @param c * @return String */ public static String trim(String text, char c) { if (text == null) { return EMPTY; } int i = 0; int j = text.length(); while ((i < j) && (text.charAt(i) == c)) { i++; } while ((i < j) && (text.charAt(j - 1) == c)) { j--; } return ((i > 0) || (j < text.length())) ? text.substring(i, j) : text; } }