Here you can find the source of replaceWhitespace(final String value, final boolean stripExtras)
Parameter | Description |
---|---|
value | the string to work with |
stripExtras | if true, replace multiple whitespace characters with a single character. |
public static String replaceWhitespace(final String value, final boolean stripExtras)
//package com.java2s; /*// w ww .j a va 2 s . c o m * JBoss, Home of Professional Open Source. * * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. * * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. */ public class Main { /** * Replaces all "whitespace" characters from the specified string with space characters, where whitespace includes \r\t\n and * other characters * * @param value the string to work with * @param stripExtras if true, replace multiple whitespace characters with a single character. * @see java.util.regex.Pattern */ public static String replaceWhitespace(final String value, final boolean stripExtras) { return replaceWhitespace(value, " ", stripExtras); //$NON-NLS-1$ } /** * Replaces all "whitespace" characters from the specified string with space characters, where whitespace includes \r\t\n and * other characters * * @param value the string to work with * @param replaceWith the character to replace with * @param stripExtras if true, replace multiple whitespace characters with a single character. * @see java.util.regex.Pattern */ public static String replaceWhitespace(final String value, final String replaceWith, final boolean stripExtras) { String rv = value.replaceAll("\\s+", replaceWith); //$NON-NLS-1$ if (stripExtras) rv = removeExtraWhitespace(rv); return rv; } /** * Replaces multiple sequential "whitespace" characters from the specified string with a single space character, where * whitespace includes \r\t\n and other characters * * @param value the string to work with * @see java.util.regex.Pattern */ public static String removeExtraWhitespace(final String value) { return value.replaceAll("\\s\\s+", " "); //$NON-NLS-1$//$NON-NLS-2$ } }