Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

Idiom #274 Remove all white space characters

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

#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()) ;
using System;
using System.Linq;
var t = new string(s.Where(c => !Char.IsWhiteSpace(c)).ToArray());

New implementation...