In Pharo, there's a very useful method
String>expandMacrosWith:
, virtually without documentation. It's much like printf in C. I guess it's easily understood from a few examples, so here go:
"<1s> is replaced by the first argument, a string.
<n> is a newline, <t> is a tab.
% escapes brackets."
'<1s><n><t>%<inject><n><t>^<1s>' expandMacrosWith: 'player'
➔
'player
<inject>
^player'
"p calls printString":
'<1p>' expandMacrosWith: #(1 2 3)
➔
'#(1 2 3)'
"? prints one string or another, depending on a Boolean"
'Dear <1?Mr:Mrs> <2s>, your contract has expired.'
expandMacrosWith: false with: 'Smith'
➔
'Dear Mrs Smith, your contract has expired.'
Actually this method originally comes from the refactoring engine. It is discussed in "Pharo by Example", if I remember correctly.
ReplyDeleteHa, true. It's on page 197. <t> and <n> are missing, though.
ReplyDelete