You could also try to!int(str.strip), strip() removes whitespace from the left and right of a string. You have to import std.string for it.
On 13 January 2012 22:34, Joshua Reusch <yos...@arkandos.de> wrote: > Am 13.01.2012 22:16, Piotr Szturmaj wrote: >> >> Jorge wrote: >>> >>> My first question si very silly: >>> >>> string str = readln() >>> >>> my input is for example 123 >>> >>> how can i convert this to an integer? >> >> >> import std.conv; >> >> // then in code: >> >> auto i = to!int(str); > > > the string returned by readln() ends with NL ('\n'), which causes > std.conv.to to raise an ConvException. You also must slice it away: > > auto i = to!int(str[0..$-1]); > > or you use std.conv.parse, which ignores the characters after the value and > removes the converted characters from the string.