Re: Absolute beginner

2012-01-14 Thread Matej Nanut
I've never noticed std.conv.parse takes a radix argument, silly me. And will take a look at readf from std.stream, definitely. Thanks! On 14 January 2012 01:20, Justin Whear wrote: > On Fri, 13 Jan 2012 23:05:19 +0100, Matej Nanut wrote: > >> While we're at it: what's the best way to parse in a

Re: Absolute beginner

2012-01-13 Thread Justin Whear
On Fri, 13 Jan 2012 23:05:19 +0100, Matej Nanut wrote: > While we're at it: what's the best way to parse in a formatted manner? > For example, if I want to get 5 hexadecimal digits converted into an > uint? And I want to simultaneously advance the string? > > "sscanf" seems fiddly and unsafe. >

Re: Absolute beginner

2012-01-13 Thread H. S. Teoh
On Fri, Jan 13, 2012 at 11:05:19PM +0100, Matej Nanut wrote: > While we're at it: what's the best way to parse in a formatted manner? > For example, if I want to get 5 hexadecimal digits converted into an > uint? [...] Have you tried: import std.conv; ... uint val = parse!

Re: Absolute beginner

2012-01-13 Thread Matej Nanut
While we're at it: what's the best way to parse in a formatted manner? For example, if I want to get 5 hexadecimal digits converted into an uint? And I want to simultaneously advance the string? "sscanf" seems fiddly and unsafe. On 13 January 2012 22:56, bearophile wrote: > Timon Gehr: > >> read

Re: Absolute beginner

2012-01-13 Thread bearophile
Timon Gehr: > readln() includes the trailing newline character in the resulting > string. You can use std.string.strip to remove leading and trailing > whitespace: Time ago I have asked Andrei to modify the to!int conversion to work as Python, ignoring leading and trailing whitespace: >>> s =

Re: Absolute beginner

2012-01-13 Thread Timon Gehr
On 01/13/2012 10:34 PM, Jorge wrote: Thanks for your answer but: import std.stdio; import std.conv; void main() { write("Insert number: "); string s = readln(); auto i = to!int(s); } compiles but after i enter a number and press the enter key i get: std.conv.ConvExcepti

Re: Absolute beginner

2012-01-13 Thread Matej Nanut
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 wrote: > Am 13.01.2012 22:16, Piotr Szturmaj wrote: >> >> Jorge wrote: >>> >>> My first question si very silly: >>> >

Re: Absolute beginner

2012-01-13 Thread Jorge
Ok, it works fine. Thx to you all ;-) and sorry for my noob question.

Re: Absolute beginner

2012-01-13 Thread Joshua Reusch
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'), w

Re: Absolute beginner

2012-01-13 Thread Jorge
Thanks for your answer but: import std.stdio; import std.conv; void main() { write("Insert number: "); string s = readln(); auto i = to!int(s); } compiles but after i enter a number and press the enter key i get: std.conv.ConvException@.\..\..\src\phobos\std\conv.d(1595):

Re: Absolute beginner

2012-01-13 Thread Piotr Szturmaj
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);