I have a text file that I need to convert each line into integer.
The lines can begin with '#' to indicate a comment. Also, after the data it might be inline comment too...again indicated by '#'
So I have the example below:
QString time = "5000 #this is 5 seconds"; // OK
QString time = " 5000 # this is 5 seconds"; // OK..free spaceis allowed at start
QString time = "5000.00 #this is 5 seconds"; // invalid...no decimal
QString time = "s5000 # this is 5 seconds"; // invalid...does not start with numerical character
How can I take care of these cases? I mean in all the 4 example above except the last two I need to extract "5000". How to find out the last one is invalid?
So I mean what is the best fail-proof code to handle this task?