<div dir="ltr">There is nothing exactly like what Python does. There are options though:<br><br>- You can use io_lib:format which returns a, possibly deep, list of characters which is the the representation of format string and the arguments. So:<br>
<br>Phrase = io_lib:format("The ~p in the ~p", ["cat", "hat"])<br><br>Depending on what you are going to do, you may have to apply lists:flatten to the string to get a flat list. io_lib:format has the same format options as io:format, and is in fact called by io:format to generate the output string.<br>
<br>- A more direct but less general way is to concatenate the string directly:<br><br>Cat = "cat",<br>Hat = "hat",<br>Phrase = "The " ++ Cat ++ " in the " ++ Hat<br><br>From your question I would guess it is the 1st version you want,<br>
<br>Robert<br><br><div class="gmail_quote">2008/10/17 David Cabana <span dir="ltr"><<a href="mailto:drcabana@gmail.com">drcabana@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Consider the result of evaluating the following in an erl console:<br>io:format("The ~p in the ~p", ["cat", "hat"]).<br><br>The strings "cat" and "hat" are substituted for the occurrences of ~p, and a string is printed to the console.<br>
Is there a way to bind that string to a variable instead of printing it to the console?<br><br>What I am after is a facility somewhat like the one used in the Python example below:<br>phrase = "The %s in the %s" % ("cat", "hat")<br>
<br>Evaluating the example above results in the variable 'phrase' taking the value "The cat in the hat".<br> <br>The similarity to the io:format behavior is clear. The Python idiom is useful, and I have been looking for something<br>
similar in Erlang, without luck. Before I try to concoct such a thing, I thought I'd ask whether it already exists.<br><br>Thanks,<br>David<br><br></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br></div>