Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static CharSequence getTrimmedString(CharSequence src) { if (src == null || src.length() == 0) { return src; } while (src.length() > 0 && (src.charAt(0) == '\n' || src.charAt(0) == ' ')) { src = src.subSequence(1, src.length()); } while (src.length() > 0 && (src.charAt(src.length() - 1) == '\n' || src.charAt(src.length() - 1) == ' ')) { src = src.subSequence(0, src.length() - 1); } return src; } }