Java Regex String Replace Whitespace replaceWhiteSpacesByMinusSign(final String value)

Here you can find the source of replaceWhiteSpacesByMinusSign(final String value)

Description

Replace white space characters (1..n) by the minus sign character

License

Open Source License

Parameter

Parameter Description
value input value

Return

string value

Declaration

public static String replaceWhiteSpacesByMinusSign(final String value) 

Method Source Code


//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    /** String constant containing 1 minus sign character '-' */
    public final static String STRING_MINUS_SIGN = "-";
    /** RegExp expression to match white spaces (1..n) */
    private final static Pattern PATTERN_WHITE_SPACE_MULTIPLE = Pattern.compile("\\s+");

    /**//from   www .ja va2 s .com
     * Replace white space characters (1..n) by the minus sign character
     * @param value input value
     * @return string value
     */
    public static String replaceWhiteSpacesByMinusSign(final String value) {
        return replaceWhiteSpaces(value, STRING_MINUS_SIGN);
    }

    /**
     * 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. replaceWhitespace(String searchTerm)
  2. replaceWhiteSpaces(final String value, final String replaceBy)
  3. replaceWhitespaces(String inString, String with)
  4. replaceWhitespaces(String inString, String with)
  5. replaceWhiteSpaces(String str)