[erlang-questions] How can I determine if a list is a just a string or a list of strings?
Rapsey
rapsey@REDACTED
Thu Sep 10 19:09:35 CEST 2009
I think this method is faster:
matches lists in lists, test first
[[_|_]|_] = L
mathches all lists, test second:
[_|_] = L
Sergej
On Thu, Sep 10, 2009 at 6:10 PM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:
> Magnus Falk wrote:
>
>> Hi all,
>>
>> I have a variable that can either contain a list of strings or a just a
>> string. Is there a good way to tell what kind I'm, dealing with?
>>
>> "192.168.1.18" vs. ["192.168.1.18", "192.168.1.19"]
>>
>
> The classic 'dirty trick' test is is_integer(hd(String)).
>
> BR,
> Ulf W
> --
> Ulf Wiger
> CTO, Erlang Training & Consulting Ltd
> http://www.erlang-consulting.com
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
More information about the erlang-questions
mailing list