I like the "sprintf" method, Martin - I hadn't known about that. It makes my multiple cases version neater: ]str=. 'Hello, %s.',LF,'Nice to meet you.',LF,'%s' Hello, %s. Nice to meet you. %s
]nmsdts=. >_2<\'Dave';'1/1/2001';'Fred';'2/18/2013' +----+---------+ |Dave|1/1/2001 | +----+---------+ |Fred|2/18/2013| +----+---------+ str sprintf"1 nmsdts Hello, Dave. Nice to meet you. 1/1/2001 Hello, Fred. Nice to meet you. 2/18/2013 $str sprintf"1 nmsdts 2 40 On Mon, Feb 18, 2013 at 8:32 AM, Raul Miller <[email protected]> wrote: > Here's a quick implementation: > > template=:1 :0 > assert. -. 0 e. }., I. '{}' =/ m NB. {} syntax check > assert. (,2) -: }.$y NB. need two cols: names; values > nams=. {."1 ,.y > vals=. {:"1 ,.y > subst=. vals {::~ nams i. <a > ;(+/\@e.&'{}' <@({. subst@]^:('{'=[) }.)/. ]) m > ) > > Example use: > > '{this} food' template ,:'this';'that' > that food > > or, given > > example=: 0 :0 template > Hello {name}, > Nice to meet you. > {date} > ) > > This would also be an example: > > example (;:'name date'),.'George';'today' > > FYI, > > -- > Raul > > On Mon, Feb 18, 2013 at 12:18 AM, June Kim (김창준) <[email protected]> > wrote: > > Hello > > > > I am looking for a string template library in J. Is there something like > > what's following(it's in Python): > > > >>>> """ > > ... Hello {name}, > > ... Nice to meet you. > > ... {date} > > ... """.format(**dict(name="David", date="2013.2.18")) > > '\nHello David,\nNice to meet you.\n2013.2.18\n' > >>>> print _ > > > > Hello David, > > Nice to meet you. > > 2013.2.18 > > > > > > I think I can write a verb in J, but firstly I wanted to check if there > is > > something out there already. > > > > June > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA ^me^ at acm. org is my preferred e-mail ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
