Dynamic Minimum width with Format / writefln
    Chris Katko 
    ckatko at gmail.com
       
    Wed Oct  3 00:14:03 UTC 2018
    
    
  
  - First, I'm confused. The docs say 's' is "whatever it needs to 
be". ("he corresponding argument is formatted in a manner 
consistent with its type:") But what if I specifically want a 
STRING. Because I only see floats, ints, etc. No forced string 
types.
  - Second,
This works fine in D:
     printf("%-*s|", col.width-1, col.name.toStringz());
It's a left-aligned, string with a minimum width from the first 
argument, col.width. (-1 because I'm throwing a pipe symbol on 
the end.)
Now with writefln:
     writefln("%-*s|", col.width-1, col.name);
Same format specifier, except I don't need a toStringz which is 
nice. Except it doesn't work and tries to decode col.width-1 into 
a hexadecimal number and only prints that. ("4D6EF6")
I looked through the docs:
https://dlang.org/phobos/std_format.html
  '%' Position Flags Width Separator Precision FormatChar
Width:
     empty
     Integer
     '*'
But there are then zero examples or explanations of how to use 
that option. What's going on here?
    
    
More information about the Digitalmars-d-learn
mailing list