scala - Partial Read from StdIn or String -


suppose have mathematical expression, such 1 + 5.4 * 2 ^ 3, , i'm trying tokenize it. in scala, able "peek" @ next character in stdin before deciding whether read number, or operator.

in c++, can things like

double val = 0; char letter = ' '; std::cin >> val; std::cin >> letter; 

and on input "54.6ff", val have value '54.6', , letter have value 'f'. moreover, in c++, can @ next character in string, , call cin.putback if decide want read upcoming characters number, rather operator.

so in scala, there way peek @ next character in stdin, or put characters stdin? additionally, calling stdin.readdouble() crash on inputs such "54.6ff" numberformatexception. in scala.io.stdin docs, readdouble annotated "reads double value entire line of default input". possible in scala partially read stdin?

finally, option read entire input string, , process string. there way of converting leading numbers in string double, returning double, , rest of string?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -