Here you can find the source of sanitize(String string, String spaceReplace)
Parameter | Description |
---|---|
string | The message to be sanitized. |
spaceReplace | The string to be substituted for spaces. |
public static String sanitize(String string, String spaceReplace)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a va 2 s. c om * Sanitizes the provided message, removing any non-alphanumeric characters and swapping spaces with the specified * string. * <p/> * Examples: sanitize("Hello! :) How are you?", '-') --> "Hello--How-are-you" sanitize("I am great, thank you!", * '*') --> "I*am*great*thank*you" * * @param string The message to be sanitized. * @param spaceReplace The string to be substituted for spaces. * @return The sanitized string. */ public static String sanitize(String string, String spaceReplace) { return string.replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", spaceReplace); } }