Search code examples
d

How to split array of strings (string [])?


I have got array of strings

string [] foo

array consist next data:

2014 01 02 234 124
2014 01 03 640 710
2014 01 04 234 921

I need new array of strings date, that would include only date (yyyy-MM-dd). How can I do it?


Solution

  • Here's a functional approach:

    string[] dates = foo.map!(line => line.split()[0..3].join("-")).array();