to!()() & leading/trailing whitespace

Jonathan M Davis jmdavisprog at
Mon Aug 16 16:06:47 PDT 2010

On Monday, August 16, 2010 15:35:51 bearophile wrote:
> This post is about this enhancement request of mine that recently David
> Simcha has closed as wontfix:
> This topic is about a small Phobos thing, it's not about large complex
> things as the const system. But it's relevant because I have hundreds of
> Python scripts (and many small D1 programs) that essentially load some
> numbers from textual files, process them, and write the numbers in other
> textual files. My textual files are often small, but I have many of them,
> and I like to see them processed quickly and safely, and I like to write
> those little programs in a short time. So reading numbers from a text file
> is an essential operation for me. And when I read textual files it's
> common to have leading newlines (whitespace) behind numbers.

A string with whitespace is _not_ a number. I can see why that would be 
problematic when you don't care about the whitespace, but you're converting the 
whole string, not just the numeric part. Using strip() is an extremely trivial 
workaround, and if you don't like that, there's always parse() which will strip 
out the whitespace itself. to() is for exact conversions, and whitespace is non-
numeric. If you want to parse a string, then use parse(). I totally agree with 
David on this one. All the tools that you need are there.

- Jonathan M Davis

More information about the Digitalmars-d mailing list