Jump to content

Align columns: Difference between revisions

→‎{{header|Elixir}}: String.ljust -> pad_trailing
(→‎{{header|Elixir}}: String.ljust -> pad_trailing)
Line 1,592:
=={{header|Elixir}}==
{{trans|Ruby}}
{{works with|Elixir|1.3}}
The String module of Elixir doesn't have the function of the center position adjusting.
It calls and processes the function of 'Erlang'.
Line 1,597 ⟶ 1,598:
def columns(text, alignment) do
fieldsbyrow = String.split(text, "\n", trim: true)
|> Enum.map(fn linerow -> String.split(linerow, "$", trim: true) end)
maxfields = Enum.map(fieldsbyrow, fn field -> length(field) end) |> Enum.max
colwidths = Enum.map(fieldsbyrow, fn field -> field ++ List.duplicate("", maxfields - length(field)) end)
Line 1,611 ⟶ 1,612:
end
defp adjust(field, width, :Left), do: String.ljustpad_trailing(field, width)
defp adjust(field, width, :Right), do: String.rjustpad_leading(field, width)
defp adjust(field, width, _), do: :string.centre(String.to_char_listto_charlist(field), width)
end
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.