std.format expand "%s"

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 21 06:57:01 PDT 2017


On 8/20/17 9:52 PM, jmh530 wrote:
> I'm playing around with std.format and I'm trying to figure out if there 
> is any way to identify what "%s" should expand to.
> 
> So for instance:
> int x = 1;
> auto result = x.format!"%s";
> 
> I would know that result="1". I could run "1" through unformatValue and 
> get back 1. I'm looking to see if there is a way to get back "%d": 
> really a function would be like f(x, "%s") produces "%d".
> 
> Is there anything like that in std.format?

Well, for most things, %s does not do the same thing as another 
specifier. It's only integers, which format the same as %d, and floating 
points, which format the same as %g.

For all others, the format is specified as %s.

I think what you really want is just isFloatingPoint or isIntegral.

-Steve


More information about the Digitalmars-d-learn mailing list