« first day (1311 days earlier)      last day (1548 days later) » 

11:35 AM
What's the easiest way to read a number of arbitrary length from a string?
Examples:
abc123 => 123
123abc => 123
ab123c => 123
 
@northerner extract as a string?
 
good call
So continue reading while character is a digit
 
I was asking whether you want to convert it to an int at the same time or just find the substring
 
convert to int @PeterT
I was following the code in the question stackoverflow.com/questions/56547298/shunting-yard-algorithm-c and it looks strange. I don't get why he needs to multiply by 10 etc
i.e. val = (val*10) + (tokens[i]-'0');
 
it's multiplying by 10 because people typically write numbers in the decimal system
it's what it means for a number to be one digit longer in that number-system
 
11:43 AM
@PeterT what does the -'0' at end do?
 
'0' => 48, but you want '0' => 0, so you subtract the 48
because conveniently ASCII, utf-8, etc encode the digits increasing as 0 1 2 3 ...
 
Wouldn't it be simpler just to treat it as a string and find last digit [0-9], then cast that portion of string to int?
 
there is no simple casting, you can convert it, why they didn't use something like strtoll, I don't know
 
12:04 PM
the conversion function from string to int will end up doing the exact same thing
 
12:22 PM
except with more concise code
also I don't think it's necessary to check i < tokens.length() &&
 
you can only remove it if you can guarantee that tokens[tokens.length()] is not UB and isDigit returns false for it
when parsing you need to be able to deal with malformed input
 

« first day (1311 days earlier)      last day (1548 days later) »