Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created April 5, 2018 17:31
Show Gist options
  • Select an option

  • Save run-dlang/413282d9726dbac137bf5f35033a8eea to your computer and use it in GitHub Desktop.

Select an option

Save run-dlang/413282d9726dbac137bf5f35033a8eea to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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