d简单过滤空格

原文

import std.algorithm: splitter, filter;
import std.uni: isWhite; // 或用std.ascii
import std.array: array;
import std.stdio: writeln;

string exampleText =
    "Hello           123-456-ABC    x\ny\tz\r\nwvu   goodbye";

void main()
{
    string[] tokens = exampleText
        .splitter!isWhite
//splitter为懒求值.`避免`分配临时数组
        .filter!(t => t.length > 0)
        .array;
    writeln("tokens = ", tokens);
}
posted @ 2022-10-23 10:01  zjh6  阅读(12)  评论(0)    收藏  举报  来源