Erlang/OTP Forums

Author Message

<  Erlang  ~  list_to_string ?

klm
Posted: Sat May 23, 2009 10:16 pm Reply with quote
User Joined: 11 May 2009 Posts: 18
hey !

I've got a question.

I have an Ip address and I try to change it into a string to send it into a message

{ok,Name} = inet:gethostname(),
{ok,Addr} = inet:getaddr(Name,inet),

Message = "My Ip" ++ Addr,
io:format("Test : ~p",[Message]),

it's just an example but it's to show what's my problem

I can't concatenate a string and an Ip address ( with the form {192,168,1,1} )

I try to do a tuple_to_list(Addr), but I can't also concatenate a list and a string.

how can I do a string contening the address ?

thanks !
View user's profile Send private message
ates
Posted: Sat May 23, 2009 10:52 pm Reply with quote
Joined: 23 May 2009 Posts: 3
Use inet_parse:ntoa(IP)

IP = {1,1,1,1}.
Msg = "My IP: " ++ inet_parse:ntoa(IP).
io:format("~p~n", [Msg]).
View user's profile Send private message
klm
Posted: Sun May 24, 2009 3:46 pm Reply with quote
User Joined: 11 May 2009 Posts: 18
ok thanks

I didn't knew this function, I will try it

I had found another solution with io_lib:format("~p",[Ip]),
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum