Java tutorial
//package com.java2s; public class Main { public static String removeBlanks(String content) { if (content == null) { return null; } StringBuffer buff = new StringBuffer(); buff.append(content); for (int i = buff.length() - 1; i >= 0; i--) { if (' ' == buff.charAt(i) || ('\n' == buff.charAt(i)) || ('\t' == buff.charAt(i)) || ('\r' == buff.charAt(i))) { buff.deleteCharAt(i); } } return buff.toString(); } }