Skip to content

Instantly share code, notes, and snippets.

@tomthorogood
Created April 4, 2013 14:26
Show Gist options
  • Save tomthorogood/5310782 to your computer and use it in GitHub Desktop.
Save tomthorogood/5310782 to your computer and use it in GitHub Desktop.
Way better way of finding ints in strings
int main() {
std::string foostring = "this is a test [[6379]] of the number finding system.";
auto digstart = foostring.find_first_of("1234567890");
auto tail = foostring.substr(digstart);
auto digend = tail.find_first_not_of("1234567890");
auto digit = tail.substr(0,digend);
auto digint = atoi(digit.c_str());
std::cout << digint << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment