How To Convert An Elixir Binary To A String?

前端 未结 6 1585
天命终不由人
天命终不由人 2020-12-10 02:41

So I\'m trying to convert a binary to a string. This code:

t = [{<<71,0,69,0,84,0>>}]
String.from_char_list(t)

But I\'m gettin

6条回答
  •  孤城傲影
    2020-12-10 03:19

    You can use Comprehensions

        defmodule TestModule do
          def convert(binary) do
            for c <- binary, into: "", do: <>
          end
        end
        TestModule.convert([71,32,69,32,84,32]) |> IO.puts
    

提交回复
热议问题