Here you can find the source of underscoreSpaces(String input)
public static String underscoreSpaces(String input)
//package com.java2s; //License from project: Open Source License public class Main { public static String underscoreSpaces(String input) { if (input == null) return null; String tmp = input.trim().replaceAll("\\s+", "_"); tmp = tmp.replaceAll("_+", "_"); return tmp; }//ww w .j av a2 s. c o m /** * will trim off the front and back of the string. * * if trim = " " then it is the same as str.trim() * * @param input * @param trim * @return */ public static String trim(String input, String trim) { if (input == null || trim == null || trim.isEmpty()) return input; String tmp = input; while (tmp.startsWith(trim)) { tmp = tmp.substring(trim.length()); } while (tmp.endsWith(trim)) { tmp = tmp.substring(0, tmp.length() - trim.length()); } return tmp; } }