Created
April 5, 2018 17:31
-
-
Save run-dlang/413282d9726dbac137bf5f35033a8eea 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