Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #274 Remove all white space characters

Create the string t from the string s, removing all the spaces, newlines, tabulations, etc.

let t: String = s.chars().filter(|c| !c.is_whitespace()).collect();
using System;
using System.Linq;
var t = new string(s.Where(c => !Char.IsWhiteSpace(c)).ToArray());
[Ch || Ch <- "This is a\tstring with\nwhite\rspaces", Ch /= 8, Ch /= 9, Ch /= 10, Ch /= 13, Ch /= 32 ].
import "strings"
import "unicode"
t := strings.Map(func(r rune) rune {
	if unicode.IsSpace(r) {
		return -1
	}
	return r
}, s)
import Data.Char (isSpace)
t = filter (not . isSpace) s
let t = s.replace(/\s/g,'');
String t = s.replaceAll("\\s+", "");
uses RegExpr;
t := ReplaceRegExpr('\s', s, '');
  SetLength(t, Length(s));
  i := 0;
  for Ch in S do
    if (Ch > #32) then
    begin
      Inc(i);
      t[i] := Ch;
    end;
  SetLength(t, i);
my $t = $s;
$t =~ s/\s*//g;
import re
t = re.sub('\\s', '', s)
t = s.gsub(/\s/, "")
t = s.gsub(/[[:space:]]/, "")

New implementation...