Forums

Converting strings to ints

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Converting strings to ints

Postby ChrisN » Wed Jul 16, 2008 4:44 pm

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"
ChrisN
 
Posts: 2

Re: Converting strings to ints

Postby hopscc » Wed Jul 16, 2008 6:56 pm

have a look at the .net doc on Int32.Parse.
Tho cobra conversion would be int.parse
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Converting strings to ints

Postby ChrisN » Thu Jul 17, 2008 7:20 am

Thanks, That works fine!
ChrisN
 
Posts: 2

Re: Converting strings to ints

Postby Charles » Tue Jul 22, 2008 5:15 pm

This indicates a gap in the How To's. Maybe one that covers casting, parsing and string splitting and joining.

-Chuck
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Converting strings to ints

Postby hopscc » Fri Jul 25, 2008 10:14 pm

Something like this perhaps.
Attachments
CastParse.cobra
(3.18 KiB) Downloaded 635 times
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 21 guests

cron