Using Python, how can/should I parse a string that has a number, followed by other characters, to an int? The specific problem I am trying to solve is parsing the first number out of a string containing a number followed by an arbitrary amount of other characters, including, possibly other numbers, which I am not interested in.
For example, if the string is "12//1"
I need to get just the 12
to an integer.
If you want to extract the digits in the string:
int(''.join(c for c in s if c.isdigit()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With