Java tutorial
//package com.java2s; public class Main { public static String trimString(String text) { String newText = null; if (text != null) { newText = text.replaceAll("^(\\s*)", ""); newText = newText.replaceAll("(\\s*)$", ""); } return newText; } }