Created
April 7, 2018 03:17
-
-
Save run-dlang/d946e68827eeee28560aff1342f348c1 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.stdio; | |
| void main() | |
| { | |
| string list = "3, 5, 1, , not a number, 100"; | |
| import std.algorithm; | |
| import std.string; | |
| import std.conv; | |
| import std.range : array; | |
| int[] numbers = | |
| list | |
| .split(",") | |
| .filter!((entry) { | |
| if (!isNumeric(entry.strip)) | |
| return false; | |
| else // ... even more cases? | |
| return true; | |
| }) | |
| .map!((e) => e.strip.to!int).array; | |
| assert(numbers == [3, 5, 1, 100]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment