Logo

Programming-Idioms

  • Haskell

Idiom #274 Remove all white space characters

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

import Data.Char (isSpace)
t = filter (not . isSpace) s
#include <iostream>
#include <string>
#include <algorithm>
auto t = s;
t.erase(std::ranges::remove_if(t, [](const char c) { return std::isspace(c); }).begin(),t.end()) ;

New implementation...