Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Strip trailing whitespace at end of line * * @param str * @return */ public static String rStrip(String str) { int last = str.length() - 1; int end = last; while ((end >= 0) && (str.charAt(end) <= ' ')) { end--; } if (end == last) { return str; } return str.substring(0, end + 1); } }