Java tutorial
//package com.java2s; public class Main { public static CharSequence trimTrailingWhitespace(CharSequence text) { while (text.charAt(text.length() - 1) == '\n') { text = text.subSequence(0, text.length() - 1); } return text; } }