首页 > 编程语言 > 详细

Java 删除换行

时间:2015-09-30 02:05:29      阅读:340      评论:0      收藏:0      [点我收藏+]

Java 删除换行:

/***
	 * Delete all spaces
	 * 
	 * @param input
	 * @return
	 */
	public static String deleteAllCRLF(String input) {
		return input.replaceAll("((\r\n)|\n)[\\s\t ]*", " ").replaceAll(
				"^((\r\n)|\n)", "");
	}

?

/***
	 * delete CRLF; delete empty line ;delete blank lines
	 * 
	 * @param input
	 * @return
	 */
	private static String deleteCRLFOnce(String input) {
		if (ValueWidget.isHasValue(input)) {
			return input.replaceAll("((\r\n)|\n)[\\s\t ]*(\\1)+", "$1")
					.replaceAll("^((\r\n)|\n)", "");
		} else {
			return null;
		}
	}

	/***
	 * Delete all spaces
	 * 
	 * @param input
	 * @return
	 */
	public static String deleteAllCRLF(String input) {
		return input.replaceAll("((\r\n)|\n)[\\s\t ]*", "").replaceAll(
				"^((\r\n)|\n)", "");
	}

	public static String CRLF2Blank(String input) {
		return input.replaceAll("((\r\n)|\n)[\\s\t ]*", " ").replaceAll(
				"^((\r\n)|\n)", " ").replaceAll("[ ]{2,}", " ");//注意:replace不支持正则表达式
	}
	/**
	 * delete CRLF; delete empty line ;delete blank lines
	 * 
	 * @param input
	 * @return
	 */
	public static String deleteCRLF(String input) {
		input = SystemHWUtil.deleteCRLFOnce(input);
		return SystemHWUtil.deleteCRLFOnce(input);
	}

?

?SystemHWUtil 见附件中的com.common.util.SystemHWUtil

Java 删除换行

原文:http://hw1287789687.iteye.com/blog/2246689

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!