digitalmars.D.learn - Convert output of map() to array of strings
- Andrey (10/18) Aug 15 2018 Compiler says that it can't convert result of map function to
- Paul Backus (9/19) Aug 15 2018 The result of `map` is a lazily-evaluated range. To convert it to
Hello, I have the following code:string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit);Compiler says that it can't convert result of map function to string[]... What I want: 1. Split some text into lines using separator '\n'. 2. Apply to each line a regex pattern and extract matched text. 3. Result of these operations assign to variable of type string[]. Tried to do this:list = text.split('\n').map!(line => line.matchFirst(pattern).hit).to!(string[]);but no success...
Aug 15 2018
On Wednesday, 15 August 2018 at 13:53:02 UTC, Andrey wrote:Hello, I have the following code:The result of `map` is a lazily-evaluated range. To convert it to an array, use `std.array.array`: import std.array: array; //... list = text .split('\n') .map!(line => line.matchFirst(pattern).hit) .array;string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit);Compiler says that it can't convert result of map function to string[]...
Aug 15 2018