Java String Whitespace Normalize normalizeWhitespace(String orig)

Here you can find the source of normalizeWhitespace(String orig)

Description

Replace any string of whitespace characters with a single space, and remove whitespace from the beginning and end of the string.

License

Open Source License

Return

the new string.

Declaration

public static String normalizeWhitespace(String orig) 

Method Source Code

//package com.java2s;
/*//from   w  w w.  j ava2s . c  o  m
 * Copyright 2011-2016 CAST, Inc.
 *
 * This file is part of the CAST Wicket Modules:
 * see <http://code.google.com/p/cast-wicket-modules>.
 *
 * The CAST Wicket Modules are free software: you can redistribute and/or
 * modify them under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * The CAST Wicket Modules are distributed in the hope that they will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Replace any string of whitespace characters with a single space,
     * and remove whitespace from the beginning and end of the string.
     * 
     * @return the new string.
     */
    public static String normalizeWhitespace(String orig) {
        return orig.replaceAll("\\s+", " ").trim();
    }
}

Related

  1. normalizeIndentationFromWhitespace(String str, int tabSize, boolean insertSpaces)
  2. normalizeWhitespace(final String str)
  3. normalizeWhitespace(String dirtyString)
  4. normalizeWhiteSpace(String input)
  5. normalizeWhiteSpace(String input)
  6. normalizeWhitespace(String s)
  7. normalizeWhitespace(String source)
  8. normalizeWhiteSpace(String src)
  9. normalizeWhitespace(String text)