Java Regex String Replace Whitespace replaceWhiteSpaces(final String value, final String replaceBy)

Here you can find the source of replaceWhiteSpaces(final String value, final String replaceBy)

Description

Replace white space characters (1..n) by the given replacement string

License

Open Source License

Parameter

Parameter Description
value input value
replaceBy replacement string

Return

string value

Declaration

public static String replaceWhiteSpaces(final String value, final String replaceBy) 

Method Source Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    /** RegExp expression to match white spaces (1..n) */
    private final static Pattern PATTERN_WHITE_SPACE_MULTIPLE = Pattern.compile("\\s+");

    /**/* w  ww  .  ja v  a  2  s .c  o  m*/
     * Replace white space characters (1..n) by the given replacement string
     * @param value input value
     * @param replaceBy replacement string
     * @return string value
     */
    public static String replaceWhiteSpaces(final String value, final String replaceBy) {
        return PATTERN_WHITE_SPACE_MULTIPLE.matcher(value).replaceAll(replaceBy);
    }
}

Related

  1. replaceBlank(String str)
  2. replaceBlank(String str)
  3. replaceWhitespace(final String value, final boolean stripExtras)
  4. replaceWhitespace(final String value, final boolean stripExtras)
  5. replaceWhitespace(String searchTerm)
  6. replaceWhitespaces(String inString, String with)
  7. replaceWhitespaces(String inString, String with)
  8. replaceWhiteSpaces(String str)
  9. replaceWhiteSpacesByMinusSign(final String value)