Re: Issue 1694 in dart: Add sprintf function for strings

36 views
Skip to first unread message

da...@googlecode.com

unread,
Jun 8, 2012, 3:10:57 PM6/8/12
to bu...@dartlang.org
Updates:
Summary: Add sprintf function for strings

Comment #5 on issue 1694 by seth...@google.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

(No comment was entered for this change.)

da...@googlecode.com

unread,
Jun 10, 2012, 8:38:19 PM6/10/12
to bu...@dartlang.org

Comment #6 on issue 1694 by andrew.p...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

Agreed.

da...@googlecode.com

unread,
Sep 4, 2012, 11:49:14 AM9/4/12
to bu...@dartlang.org

Comment #7 on issue 1694 by lucav...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

Hi guys! May I suggest to add something similar to Python string
formatting? It's less verbose and quite flexible
e.g.
var goofy = "Goofy";
var mickey = "Mickey Mouse";
var introduce = "May I introduce myself? My name is %s";
print(introduce%goofy); //Print "May I introduce myself? My name is Goofy"
print(introduce%mickey); //Print "May I introduce myself? My name is Mickey
Mouse"

da...@googlecode.com

unread,
Sep 29, 2012, 10:27:02 PM9/29/12
to bu...@dartlang.org

Comment #8 on issue 1694 by naddi...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

Until a native printf makes it into the language, I've written a dart
implementation of sprintf: https://github.com/Naddiseo/dart-sprintf

Should work for most format strings, please let me know (on github) if you
find a bug.

da...@googlecode.com

unread,
Apr 14, 2013, 6:40:57 AM4/14/13
to bu...@dartlang.org

Comment #9 on issue 1694 by al21000...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

Even without sprintf() like functions, adding simple padding options to
interpolated output would be extremely useful.

Something like "${10:expr}" or even "${a,b,c:expr}" (where "a,b,c" are
formatting options/modifiers) - the syntax should be unambiguous enough in
this context.

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

da...@googlecode.com

unread,
May 24, 2013, 9:43:52 AM5/24/13
to bu...@dartlang.org

Comment #10 on issue 1694 by IanDavid...@gmail.com: Add sprintf function
for strings
http://code.google.com/p/dart/issues/detail?id=1694

An alternative I've just seen on the Scala website
(http://docs.scala-lang.org/overviews/core/string-interpolation.html) shows
how you can mix interpolation with sprintf formatting.

We'd need to slightly change the Scala syntax to use a different character
than '%' to start the format, say '#' as '%' is modulo divide.

var height = 1.9;
var name = "Fred";
print("$name is $height#2.2f meters tall"); // "Fred is 1.90 meters"

var hex = 255;
print("$hex#08x");

Or with expressions: -
print("255 = $hex#08x hex"); // "255 = FF hex"

da...@googlecode.com

unread,
May 24, 2013, 9:45:52 AM5/24/13
to bu...@dartlang.org

Comment #11 on issue 1694 by IanDavid...@gmail.com: Add sprintf function
for strings
http://code.google.com/p/dart/issues/detail?id=1694

Oops. I'd also say it would be good to use an extended sprintf format for
date and time formatting, i.e. fields for the component parts but also a
locale-aware short/medium/long date indicator.

da...@googlecode.com

unread,
Jan 6, 2014, 7:49:00 PM1/6/14
to bu...@dartlang.org

Comment #12 on issue 1694 by cod...@google.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

I found myself wanting to use formatting like "%02x" today and had a
sad-face moment when I came here.

da...@googlecode.com

unread,
Jan 8, 2014, 5:40:49 AM1/8/14
to bu...@dartlang.org

Comment #13 on issue 1694 by tiagoso...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

Indeed. A bit disappointed dart reached 1.0 without this. Issue starred! :)

da...@googlecode.com

unread,
Jan 8, 2014, 5:58:02 AM1/8/14
to bu...@dartlang.org

Comment #14 on issue 1694 by jirkadan...@gmail.com: Add sprintf function
for strings
http://code.google.com/p/dart/issues/detail?id=1694

Formatting strings are so 1980. What about having the Dart version take a
reusable formatting object, like sprintf(Format.literalString('My name is
') + Format.decimal()..length=2..padWith(' ')..align=Format.left, [name]);
#justsaying

da...@googlecode.com

unread,
Jan 8, 2014, 6:49:43 AM1/8/14
to bu...@dartlang.org

Comment #15 on issue 1694 by tiagoso...@gmail.com: Add sprintf function for
strings
http://code.google.com/p/dart/issues/detail?id=1694

@#14 One word: verbosity. Sprintf may be old school but it's a very compact
way of making common and useful formats. I'm not against the existance of
other formatting tools but this one is a de-facto standard in programming
languages both classic and modern.

da...@googlecode.com

unread,
Jan 8, 2014, 7:08:46 AM1/8/14
to bu...@dartlang.org

Comment #16 on issue 1694 by an...@antonmoiseev.com: Add sprintf function
for strings
http://code.google.com/p/dart/issues/detail?id=1694

One more case when string formatting is helpful is when your strings
separated from the code that actually uses them. Imagine the situation when
you have a file with formatted string constants (user notifications, log
messages, etc.) and want to replace placeholders with the actual data.
String interpolation doesn't help here.

da...@googlecode.com

unread,
Jan 8, 2014, 8:37:29 PM1/8/14
to bu...@dartlang.org

Comment #17 on issue 1694 by andrew.p...@gmail.com: Add sprintf function
for strings
http://code.google.com/p/dart/issues/detail?id=1694

> Formatting strings are so 1980. What about having the Dart version take a
> reusable formatting object, like sprintf(Format.literalString('My name is
> ') + Format.decimal()..length=2..padWith(' ')..align=Format.left, [name]);

Jesus Christ, that's verbose! I guess conciseness is a dead art.
Reply all
Reply to author
Forward
0 new messages