[erlang-questions] Sometime it's the simple stuff...

Dave Bryson daveb@REDACTED
Thu May 1 19:43:56 CEST 2008


That did the trick! Thank you. Here's what I did:

Given an IP in the form: [{10,0,1,195}]
And a Port number: 3000

make_url(Ip,Port) ->
     [{A,B,C,D}] = Ip,
     X = io_lib:format("http://~p.~p.~p.~p:~p/",[A,B,C,D,Port]),
     lists:flatten(X).

Returns: "http://10.0.1.195:3000/"  which is exactly what I needed for  
the inets http client.


Thanks again,

Dave

On May 1, 2008, at 11:48 AM, Edwin Fine wrote:

> You didn't show the output of your io_lib:format call, but  
> io_lib:format often returns a deep list instead of just a flat list,  
> so you might need to use lists:flatten(io_lib:format(...)). Hope  
> that helps.
>
> On Thu, May 1, 2008 at 9:56 AM, Dave Bryson <daveb@REDACTED> wrote:
> I need to take an IP address in the form of "[{10,0,1,100}]" and
> create an http URL like this:  "http://10.0.1.100/".  I've tried using
> io_lib:format and successfully generated a list.  But, the inets http
> client  doesn't  like the format and complains of a malformed URL.
>
> What's the easiest way to convert an IP to the String version?
>
> Thanks!
> Dave
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>




More information about the erlang-questions mailing list