Page 1 of 1

Converting strings to ints

PostPosted: Wed Jul 16, 2008 4:44 pm
by ChrisN
Is there any way of converting strings, for example from a comman line input, to ints?

using input = File.openText("A-small.in")
s = input.readline
aNumber = input.readline to int
print aNumber


raises:
error: Cannot convert type "string" to "int"

Re: Converting strings to ints

PostPosted: Wed Jul 16, 2008 6:56 pm
by hopscc
have a look at the .net doc on Int32.Parse.
Tho cobra conversion would be int.parse

Re: Converting strings to ints

PostPosted: Thu Jul 17, 2008 7:20 am
by ChrisN
Thanks, That works fine!

Re: Converting strings to ints

PostPosted: Tue Jul 22, 2008 5:15 pm
by Charles
This indicates a gap in the How To's. Maybe one that covers casting, parsing and string splitting and joining.

-Chuck

Re: Converting strings to ints

PostPosted: Fri Jul 25, 2008 10:14 pm
by hopscc
Something like this perhaps.