digitalmars.D.learn - Way to format a string
- Nils Hensel (4/4) Jan 16 2006 Hi,
- Don Clugston (10/16) Jan 16 2006 import std.string;
- Alex Stevenson (12/18) Jan 16 2006 std.string.format does this very well:
- Nils Hensel (5/11) Jan 16 2006 Thanks a lot! It's not yet part of Skys docwiki so I missed that one :[
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, Nilsimport 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, Nilsstd.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, NilsThanks 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