Thread overview | |||||
---|---|---|---|---|---|
|
January 16, 2020 How to remove whitespace from a string | ||||
---|---|---|---|---|
| ||||
Hello, what is the way to remove whitespace from a string (not only at the beginning and end).. |
January 16, 2020 Re: How to remove whitespace from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namal | 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!
}
|
January 17, 2020 Re: How to remove whitespace from a string | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namal | 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
}
|
Copyright © 1999-2021 by the D Language Foundation