UnstableFractal
UnstableFractal

Reputation: 1422

Is there any way to use same parameter in io:format?

Is there any construction or maybe other function to do something like this:

Var = "hello",
io:format("My text is ~s[1]. And again: ~s[1]", Var).

So the output will be:

My text is hello. And again: hello

Upvotes: 0

Views: 59

Answers (2)

Roberto Aloi
Roberto Aloi

Reputation: 30985

It seems overkill to me, but you could do something like:

Vars = lists:duplicate(3, "hello").
io:format("One: ~s, two: ~s, three: ~s.", Vars).

Upvotes: 1

yuejunwei
yuejunwei

Reputation: 26

  1. the second parameter of io:format() should be a list.
  2. you can do it this way: io:format("My text is ~s[1]. And again: ~s[1]", [Var, Var]).

Upvotes: 1

Related Questions