digitalmars.D.learn - Way to format a string
- Nils Hensel <nils.hensel web.de> Jan 16 2006
- Don Clugston <dac nospam.com.au> Jan 16 2006
- Alex Stevenson <ans104 cs.york.ac.uk> Jan 16 2006
- Nils Hensel <nils.hensel web.de> Jan 16 2006
Hi, I'd like to know if there's a D way to format a char[] the way printf does? Thanks, Nils
Jan 16 2006
Nils Hensel wrote:Hi, I'd like to know if there's a D way to format a char[] the way printf does? Thanks, Nils
import std.string; import std.stdio; void main() { int x=10; real y = 1.0/17; char [] s = format("x=", x, "y = %.8f", y); writefln(s); }
Jan 16 2006
Nils Hensel wrote:Hi, I'd like to know if there's a D way to format a char[] the way printf does? Thanks, Nils
std.string.format does this very well: import std.string; void somefunc() { char[] aString = format( "String! %d%f%s", 10, 10.0f, "foo" ); //The D style use is also supported: char[] bString = format( "String! ", 10, 10.0f, "foo" ); //aString and bString are equal... } There's also sformat for a sprintf style call where you pass a char[] buffer as the first argument
Jan 16 2006
Nils Hensel schrieb:Hi, I'd like to know if there's a D way to format a char[] the way printf does? Thanks, Nils
Thanks a lot! It's not yet part of Skys docwiki so I missed that one :[ Guess I have to look up the original docs more often. Regards, Nils
Jan 16 2006









Don Clugston <dac nospam.com.au> 