www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Conversion (silly question, sorry)

reply renoir <renato rexlen.it> writes:
Sorry for the silly question:
how can i convert from string to int? And viceversa from int to string?
Thx.
Jan 01 2008
next sibling parent Derek Parnell <derek psych.ward> writes:
On Tue, 01 Jan 2008 18:32:32 -0500, renoir wrote:

 Sorry for the silly question:
 how can i convert from string to int? And viceversa from int to string?
 Thx.

Have a look at the std.conv module. string s; double f; s = std.conv.to!(string)(23.45); f = std.conv.to!(double)(s); -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
Jan 01 2008
prev sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"renoir" <renato rexlen.it> wrote in message 
news:fleiig$28gg$1 digitalmars.com...
 Sorry for the silly question:
 how can i convert from string to int? And viceversa from int to string?
 Thx.

If you're using D1, use std.string.toString to convert most basic types to strings and std.conv.toInt to convert from strings to ints.
Jan 01 2008
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Jarrett Billingsley wrote:
 "renoir" <renato rexlen.it> wrote in message 
 news:fleiig$28gg$1 digitalmars.com...
 Sorry for the silly question:
 how can i convert from string to int? And viceversa from int to string?
 Thx.

If you're using D1, use std.string.toString to convert most basic types to strings and std.conv.toInt to convert from strings to ints.

Or get std2 from dsource and use things like std2.conv.to!(double)(s). http://www.dsource.org/projects/std2 --bb
Jan 01 2008