Simple question but I am having trouble. I have an String input that is in this format 12:43
. (MM:SS).
I am trying to convert this string in to int
(seconds). The only part I don't know how to do is how to get 12
and 43
without getting invalid double error
. Because it is containing that ":"
in the string, I can't do the usual Parse.parseInt(string);
.
parseInt() method only works with string type variables. Hence, the character 'a' is converted into a String .
Description. The atoi() function converts a character string to an integer value. The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number.
One effective way to convert a string object into a numeral int is to use the stoi() function. This method is commonly used for newer versions of C++, with is being introduced with C++11. It takes as input a string value and returns as output the integer version of it.
split
the string according to :
int
in the resulting array, apply parseInt
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