When I do this sort of thing, I usually just use a replace function like
"stringreplace" (from stdlib.ijs), probably already present in your j
locale. For example:
template=. 'Hello {nm},',LF,'nice to meet you.',LF,'{dt}'
template stringreplace~ ,('{nm}';'{dt}'),.'David';'1/1/2013'
Hello David,
nice to meet you.
1/1/2013
The "~" version is nicer because it leaves the constant template on the
left and allows us to more naturally supply multiple arguments on the
right, e.g.
]nmsdts=. >_2<\<;._1 ' Dave 1/1/2001 Fred 1/2/2013'
+----+--------+
|Dave|1/1/2001|
+----+--------+
|Fred|1/2/2013|
+----+--------+
(<template) stringreplace~ &> ,&.>(<'{nm}';'{dt}'),.&.><"1 nmsdts
Hello Dave,
nice to meet you.
1/1/2001
Hello Fred,
nice to meet you.
1/2/2013
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
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm