Java examples for java.lang:String New Line
remove Newlines Tabs And Spaces
//package com.java2s; public class Main { public static void main(String[] argv) { String input = "book\t2s.com"; System.out.println(removeNewlinesTabsAndSpaces(input)); }//from www . j av a2s . c o m private static String removeNewlinesTabsAndSpaces(String input) { String output = input; //remove newlines output = output.replaceAll("\n", ""); output = output.replaceAll("\r", ""); //remove tabs output = output.replace("\t", ""); //remove whitespace before and after a comma output = output.replaceAll("( *)(,)( *)", "$2"); //remove whitespace before and after the string, and return it return output.trim(); } }