[erlang-questions] Question re io:format and string handling

David Cabana drcabana@REDACTED
Fri Oct 17 16:26:49 CEST 2008

Consider the result of evaluating the following in an erl console:
io:format("The ~p in the ~p", ["cat", "hat"]).

The strings "cat" and "hat" are substituted for the occurrences of ~p, and a
string is printed to the console.
Is there a way to bind that string to a variable instead of printing it to
the console?

What I am after is a facility somewhat like the one used in the Python
example below:
phrase = "The %s in the %s" % ("cat", "hat")

Evaluating the example above results in the variable 'phrase' taking the
value "The cat in the hat".

The similarity to the io:format behavior is clear.  The Python idiom is
useful, and I have been looking for something
similar in Erlang, without luck.  Before I try to concoct such a thing, I
thought I'd ask whether it already exists.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081017/a25dbb29/attachment.htm>

More information about the erlang-questions mailing list