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.

[Ch || Ch <- "This is a\tstring with\nwhite\rspaces", Ch /= 8, Ch /= 9, Ch /= 10, Ch /= 13, Ch /= 32 ].

using list comprehension
#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...