Java examples for java.util.regex:Match New Line
fix Whitespaces by removing new lines, tabs and multiple spaces via regular expression
//package com.java2s; public class Main { public static void main(String[] argv) { String sqlString = "java2s.com"; System.out.println(fixWhitespaces(sqlString)); }//from w w w. ja v a 2 s.c o m public static String fixWhitespaces(String sqlString) { // remove newlines & tabs sqlString = sqlString.replaceAll("[\\n\\t]", ""); // remove multiple spaces sqlString = sqlString.replaceAll("[ ]+", " "); return sqlString; } }