www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to remove whitespace from a string

reply Namal <sotis22 mail.ru> writes:
Hello, what is the way to remove whitespace from a string (not 
only at the beginning and end)..
Jan 16 2020
next sibling parent Paul Backus <snarwin gmail.com> writes:
On Thursday, 16 January 2020 at 13:36:10 UTC, Namal wrote:
 Hello, what is the way to remove whitespace from a string (not 
 only at the beginning and end)..
import std.algorithm: filter; import std.uni: isWhite; import std.stdio: writeln; void main() { string s = " hello world ! "; writeln(s.filter!(c => !c.isWhite)); // prints: helloworld! }
Jan 16 2020
prev sibling parent Marcone <marcone email.com> writes:
On Thursday, 16 January 2020 at 13:36:10 UTC, Namal wrote:
 Hello, what is the way to remove whitespace from a string (not 
 only at the beginning and end)..
import std; void main(){ string name = " Marvin Will "; writeln(name.replace(" ", "")); // MarvinWill }
Jan 17 2020