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);
- }
时间: 2024-11-04 13:22:36