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

Ulf Wiger ulf@REDACTED
Fri Oct 17 16:38:34 CEST 2008

io_lib:format(Format, Args) is the formatting function
used by io:format/2, and returns a (non-flat) string.

Ulf W

2008/10/17 David Cabana <drcabana@REDACTED>:
> 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.
> Thanks,
> David
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list