[erlang-questions] Simle Erlang Question (Binary "String" to Erlang "String")

Anders Nygren <>
Sun Sep 28 04:50:05 CEST 2008


On Sat, Sep 27, 2008 at 7:33 PM, David Lloyd <> wrote:
>
> Hello,
>
> I've pasted an erlang shell session below but I'll ask my question here
> so you don't have to wade through it if you don't want to.
>
> I have gotten this:
>
>  3> {ok, File}=file:read_file("hello.b64").
>  {ok,<<"SGVsbG8sIHdvcmxkIQ==\n">>}
>

19> binary_to_list(<<"SGVsbG8sIHdvcmxkIQ==\n">>).
"SGVsbG8sIHdvcmxkIQ==\n"

> I want to make File into an Erlang string so that effectively if I asked
> for its value in the shell I'd get something like this:
>
>  4> File.
>  "SGVsbG8sIHdvcmxkIQ==\n"
>
> I've been reading "Programming Erlang" by Joe Armstrong, the online R12B
> reference manual, the "Stdlib" documentation and "Concurrent Programming
> in Erlang" (or at least the parts that are publically released) in which
> Joe Armstrong is one of the authors.


In addition to the stdlib documentation, there are a lot of useful things
hiding in the module erlang in the kernel application. That is where You
will find binary_to_list.

/Anders

>
> However, I can't quite work out the right section or way to do what I'd
> like to do nor can I figure out a query to put to google that doesn't
> come back with too many answers (it seems erlang string and bit are
> quite common).
>
> Any pointers?
>
> DSL
>
> ---
>
> bash-3.2$ erl
> Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0]
> [kernel-poll:false]
>
> Eshell V5.5.5  (abort with ^G)
> ok
> 8> bash-3.2$ erl
> Erlang (BEAM) emulator version 5.5.5 [source] [async-threads:0]
> [kernel-poll:false]
>
> Eshell V5.5.5  (abort with ^G)
> 1> {ok, File} = file:read_file("hello.b64").
> {ok,<<"SGVsbG8sIHdvcmxkIQ==\n">>}
> 2> File.
> <<"SGVsbG8sIHdvcmxkIQ==\n">>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list