ExPrintf – printf / sprintf for Elixir
In Elixir (elixir-lang) or Erlang, io#format takes care of string-formatting. However, its format styling is somewhat different from the sprintf / printf ones.
Eventually, it would be expected to get accustomed to io#format style, but for alleviating the learning process, I tried to write a wrapper to do the conversion.
The following is an example, and more detail is in the GitHub repo.
defmodule Sample do import ExPrintf def test do printf("number = %d\n", ) # -> number = 10 IO.puts sprintf("string = %s", ["abc"]) # -> string = abc format = parse_printf("format = %d %.2f\n") IO.inspect format # -> "format = ~w ~.2f\n" :io.format(format, [10, 10.153]) # -> format = 10 10.15 end end Sample.test
$ mix run sample.ex number = 10 string = abc "format = ~w ~.2f\n" format = 10 10.15