Here you can find the source of chompAllAndTrim(String str)
Remove the end of line and tab characters from a String.
Parameter | Description |
---|---|
str | the String to chop last character from, may be null |
null
if null String input
public static String chompAllAndTrim(String str)
//package com.java2s; /*/*from w w w . j a v a 2 s .co m*/ * Copyright (c) 2007-2016 AREasy Runtime * * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software"); * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either version 2.1 of the License, * or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT, * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ public class Main { /** * <p>Remove the end of line and tab characters from a String. Also this method apply a trimming procedure</p> * <p/> * <p>If the String contains <code>\r\n</code> and <code>\t</code>, then remove them.</p> * <p/> * <pre> * StringUtility.chop(null) = null * StringUtility.chop("") = "" * StringUtility.chop("abc \r") = "abc" * StringUtility.chop("abc\n") = "abc" * StringUtility.chop("abc\r\n") = "abc" * StringUtility.chop("a bc") = "a bc" * StringUtility.chop("abc\nabc") = "abcab" * StringUtility.chop("a") = "" * StringUtility.chop("\r") = "" * StringUtility.chop("\n") = "" * StringUtility.chop("\r\n") = "" * </pre> * * @param str the String to chop last character from, may be null * @return String without last character, <code>null</code> if null String input */ public static String chompAllAndTrim(String str) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) != '\n' && str.charAt(i) != '\r' && str.charAt(i) != '\t') buffer.append(str.charAt(i)); } str = buffer.toString(); buffer = null; return str; } /** * Append a new string arguments into an original text. */ public static String append(String original, String argStr) { if (isNotEmpty(argStr)) return (original + argStr); else return original; } /** * <p>Checks if a String is not empty ("") and not null.</p> * <p/> * <pre> * StringUtility.isNotEmpty(null) = false * StringUtility.isNotEmpty("") = false * StringUtility.isNotEmpty(" ") = true * StringUtility.isNotEmpty("bob") = true * StringUtility.isNotEmpty(" bob ") = true * </pre> * * @param str the String to check, may be null * @return <code>true</code> if the String is not empty and not null */ public static boolean isNotEmpty(String str) { return str != null && str.length() > 0; } }