Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #274 Remove all white space characters

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

import "strings"
import "unicode"
t := strings.Map(func(r rune) rune {
	if unicode.IsSpace(r) {
		return -1
	}
	return r
}, s)
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 Data.Char (isSpace)
t = filter (not . isSpace) s
let t = s.replace(/\s/g,'');
  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);
uses RegExpr;
t := ReplaceRegExpr('\s', s, '');
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();

New implementation...