How to string format with unicode args

I’m new to elixir and I want to know how to format a string with unicode args


IO.puts(:io_lib.format("hello ~10s ~n", ["👻"]))


hello       ð» 


hello       👻

I think you’re sort of over complicating it, you can just interpolate it directly:

iex(2)> ghost = "👻"
iex(3)> IO.puts "Hello #{ghost}"
Hello 👻

Thank you for your answer. It is true that interpolation can solve the problem, but I am in the initial stage of learning elixir. I am not trying to solve a specific problem, I just want to explore more possibilities :wink:

Well, if you want to learn Elixir, use Elixir constructs, not Erlang ones. :stuck_out_tongue: Not yet at least.

According to the docs:

If and only if the Unicode translation modifier is used in the format string (that is, ~ts or ~tc), the resulting list can contain characters beyond the ISO Latin-1 character range (that is, numbers > 255)

I find using the iex h helper very useful in these cases.

iex> h :io_lib.format


iex> IO.puts(:io_lib.format("hello ~10ts ~n", ["👻"]))
hello          👻

thanks! very helpful! :slight_smile: