Removes all carriage returns from a string - Java java.lang

Java examples for java.lang:String New Line

Description

Removes all carriage returns from a string

Demo Code

/**/* www .j a  va2  s.  co  m*/
 * Copyright (c) 2005-2006 Aptana, Inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html. If redistributing this code,
 * this entire header must remain intact.
 */
import java.text.MessageFormat;

public class Main{
    /**
     * EMPTY
     */
    public static final String EMPTY = "";
    /**
     * Removes all carriage returns from a string
     * 
     * @param text
     *            The string to strip of '\n'
     * @return The string minus the carriage returns
     */
    public static String stripCarriageReturns(String text) {
        if (text == null) {
            return null;
        }

        return text.replaceAll("\n", StringUtils.EMPTY); //$NON-NLS-1$
    }
}

Related Tutorials