Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
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:]]/, "")
let t: String = s.chars().filter(|c| !c.is_whitespace()).collect();