如何在Erlang中将整数列表连接为字符串? [英] How to concat a list of integers to a string in Erlang?

查看:322
本文介绍了如何在Erlang中将整数列表连接为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的元组:

I have this tuple that looks like this:

{127,0,0,1}

现在我想将该元组作为字符串 127.0.0.1 到外部库(地理IP库)。将此元组转换为字符串的最佳方法是什么?

Now I want to pass that tuple as the string "127.0.0.1" to an external lib (a geo IP lib). What's the best way to convert this tuple to the string?

推荐答案

您可以使用以下代码:

ip_to_string({I1, I2, I3, I4}) ->
    lists:concat([I1,".",I2,".",I3,".",I4]);
ip_to_string({v6, Addr}) ->
    inet_parse:ntoa(Addr).

这篇关于如何在Erlang中将整数列表连接为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆