class: Stream
authorClaus Gittinger <cg@exept.de>
Thu, 15 May 2014 09:59:49 +0200
changeset 16453 690e4afd2a5d
parent 16452 2c3e39ef6902
child 16454 ea42dcd0ad0a
class: Stream added: #format:with: a convenience utility
Stream.st
--- a/Stream.st	Thu May 15 09:59:16 2014 +0200
+++ b/Stream.st	Thu May 15 09:59:49 2014 +0200
@@ -196,6 +196,7 @@
 
 
 
+
 !Stream methodsFor:'accessing'!
 
 contents
@@ -2978,6 +2979,24 @@
     "Modified: 7.5.1996 / 23:54:53 / stefan"
 !
 
+format:formatSpec with:args
+    "convenient formatted printing:
+        %1..%9  - positional parameters from args-collection
+        %(name) - named parameter from args-dictionary
+        %%      - escape for %
+        %<cr>   - cr (also tab, nl)"
+
+    formatSpec expandPlaceholders:$% with:args on:self
+
+    "
+     1 to: 10 do:[:i |
+        Transcript 
+            format:'[%1] Hello %2 World - this is %3%<cr>' 
+            with:{i . 'my' . 'nice'}
+     ].
+    "
+!
+
 next:count put:anObject
     "put the argument, anObject count times onto the receiver.
      This is only allowed, if the receiver supports writing."
@@ -3506,11 +3525,11 @@
 !Stream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.218 2014-05-07 13:36:16 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.219 2014-05-15 07:59:49 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.218 2014-05-07 13:36:16 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Stream.st,v 1.219 2014-05-15 07:59:49 cg Exp $'
 ! !