Java examples for java.lang:String Trim
trim a string from right
//package com.java2s; public class Main { public static void main(String[] argv) { String text = "java2s.com"; System.out.println(rtrim(text)); }/*from w ww . j a v a 2s.com*/ public static final String rtrim(final String text) { return rtrim(text, null); } public static final String rtrim(final String text, String trimText) { if (text == null) { return null; } if (trimText == null) { trimText = " "; } int pos = text.length() - 1; for (; pos >= 0; pos--) { if (trimText.indexOf(text.charAt(pos)) < 0) { break; } } return text.substring(0, pos + 1); } }