Created
April 4, 2013 14:26
-
-
Save tomthorogood/5310782 to your computer and use it in GitHub Desktop.
Way better way of finding ints in strings
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
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