Removes any whitespace from a String, correctly handling surrogate characters
@param string String to process
@return String with any whitespace removed
760177
public static String removeWhitespace(String string) {

        if (string == null || string.length() == 0) {
            return string;
        } else {
            int codePoints = string.codePointCount(0, string.length());
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < codePoints; i++) {
                int offset = string.offsetByCodePoints(0, i);

                int nextCodePoint = string.codePointAt(offset);
                if (!Character.isWhitespace(nextCodePoint)) {
                    sb.appendCodePoint(nextCodePoint);
                }
            }

            if (string.length() == sb.length()) {
                return string;
            } else {
                return sb.toString();
            }
        }
    }
1250413
public static function sanitize_string($string)
    {
        $string = self::remove_accents($string);
        $string = strtolower($string);
        $string = preg_replace('/[^a-zA-Z 0-9]+/', '', $string);
        $string = self::strip_space($string);

        return $string;
    }
503631
protected String beforeParse(String string)
	{
		if (preParseCallback == null)
		{
			return string;
		}
		
		return preParseCallback.process(string);
	}
463155
function(str) {
    return trim(str).replace(/([\r\n\s　])+/g, function(match, whitespace) {
      return whitespace === '　' ? whitespace : ' ';
    });
  }
525087
public static final boolean stringIsBlank(final String string) {

        if (string == null || string.length() == 0) {
            return true;
        }

        int stringLength = string.length();
        for (int i = 0; i < stringLength; i++) {
            if (Character.isWhitespace(string.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }
881184
private static String unescape(String string) {
    return StringUtils.unEscapeString(string, StringUtils.ESCAPE_CHAR, 
                                      charsToEscape);
  }
1181545
private function clean(string $string, bool $space_remove = true)
    {
        $string = trim($string);
        if ($space_remove) {
            $string = str_replace(' ', '-', $string);
        }
        return preg_replace('/[^A-Za-z0-9\-][_]/', '', $string);
    }
208992
public static function firstSpace($string) {
		$firstSpace = strpos($string, " ");
		return ($firstSpace === false)? strlen($string) : $firstSpace;
	}
194490
public function removeTags($string)
    {
        // Remove HTML Tags:
        
        $string = preg_replace('/<[^>]*>/', ' ', $string);
        
        // Remove Control Characters:
        
        $string = str_replace("\r", '',  $string);  // replace with empty space
        $string = str_replace("\n", ' ', $string); // replace with single space
        $string = str_replace("\t", ' ', $string); // replace with single space
        
        // Remove Multiple Spaces:
        
        $string = trim(preg_replace('/ {2,}/', ' ', $string));
        
        // Answer String:
        
        return $string;
    }
148766
public static String cleanWhitespace(String str) {
        int length = str.length();

        StringBuffer buf = new StringBuffer(length);
        for (int i=0; i<length; i++) {
            char c = str.charAt(i);
            if (Character.isWhitespace(c)) {
                buf.append(' ');
            }
            else {
                buf.append(c);
            }
        }

        return buf.toString();
    }
934148
private static function uncompressByteString($string)
    {
        $uncompressedString = '';
        $strLen = strlen($string);
        for ($i = 0; $i < $strLen; ++$i) {
            $uncompressedString .= $string[$i] . "\0";
        }

        return $uncompressedString;
    }
76304
static String sanitize(String string) {
        return WHITESPACE.matcher(string.trim()).replaceAll(DASH);
    }
1022624
private function filterSpecialCharacters($string)
    {
        $string = str_replace('<', ' <',
            $string); // This is need, otherwise this: <h1>something</h1><h2>something</h2> will result in somethingsomething
        $string = strip_tags($string);
        $string = trim($string);
        $string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string); // Remove special alphanumeric characters
        $string = str_replace(array('+', '=', '!', ',', '.', ';', ':', '?'), ' ',
            $string); // Replace sentence breaking charaters with spaces
        $string = preg_replace("/[\r\n]+/", " ", $string); // Replace multiple newlines with a single space.
        $string = preg_replace("/[\t]+/", " ", $string); // Replace multiple tabs with a single space.
        $string = preg_replace("/[^a-zA-Z0-9 ]/", '',
            $string); // Filter out everything that is not alphanumeric or a space
        $string = preg_replace('!\s+!', ' ', $string); // Replace multiple spaces with a single space
        return $string;
    }
229364
function toSpaceCase (string) {
  return clean(string).replace(/[\W_]+(.|$)/g, function (matches, match) {
    return match ? ' ' + match : '';
  });
}
120057
function( text ){
			if(text && text.length){
				var i = text.length,
					x = 0;

				// turn all whitespace chars at end into spaces
				while (i--) {
					if(this.isOnlyWhiteSpace(text[i])){
						text = this.replaceCharAt( text, i, ' ' );
					}else{
						break;
					}
				}

				// turn all whitespace chars at start into spaces
				i = text.length;
				while (x < i) {
					if(this.isOnlyWhiteSpace(text[x])){
						text = this.replaceCharAt( text, i, ' ' );
					}else{
						break;
					}
					x++;
				}
			}
			return this.trim(text);
		}
1362934
def remove_whitespace(text_string):
    '''
    
    '''
    if text_string is None or text_string == "":
        return ""
    elif isinstance(text_string, str):
        return " ".join(text_string.split())
    else:
        raise InputError("none type or string not passed as an argument")
999529
public static function compress($string)
    {
        $result = '';

        $tokens = self::tokenize($string);

        $whitespace = true;
        foreach ($tokens as $token) {
            // Skip comment tokens
            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
                continue;
            }
            // Remove extra whitespace in reserved words (e.g "OUTER     JOIN" becomes "OUTER JOIN")
            elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_TOPLEVEL) {
                $token[self::TOKEN_VALUE] = preg_replace('/\s+/',' ',$token[self::TOKEN_VALUE]);
            }

            if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
                // If the last token was whitespace, don't add another one
                if ($whitespace) {
                    continue;
                } else {
                    $whitespace = true;
                    // Convert all whitespace to a single space
                    $token[self::TOKEN_VALUE] = ' ';
                }
            } else {
                $whitespace = false;
            }

            $result .= $token[self::TOKEN_VALUE];
        }

        return rtrim($result);
    }