Hello,
How to identify the input type? For example, I want to get an input from the user with the readline()
command. How can I tell if this input is a number or a string?
Thank you.
Hello,
How to identify the input type? For example, I want to get an input from the user with the readline()
command. How can I tell if this input is a number or a string?
Thank you.
The input you will get, will always be a string.
You can test whether it is a number using parse
, cf. Numbers · The Julia Language
or also the thread Type-safe conversion of strings to numbers
You should use tryparse
if you intend to check if it is what you want, not parse
which will raise an exception.
Hi,
Thank you so much.
I wrote a code like below:
print("Please enter something: ")
a = readline()
if ((tryparse(Int, a) == nothing))
println("You have entered a string")
else
println("You have entered a number")
end