[erlang-questions] Split string in nested list

Jesper Louis Andersen <>
Fri Feb 11 18:02:40 CET 2011


On Fri, Feb 11, 2011 at 17:50, shk <> wrote:

> I have list of next view:
>
> [[""],[],[]]

I assume you mean that  is a string and not an atom
in the following:

5> [string:tokens(S, "@") || [S] <-
[[""],[""],[""]]].
[["admin","localhost"],
 ["localhost","localhost"],
 ["user","localhost"]]
6>

But you may want to pull out the underlying strings out of the lists
first depending on what you are trying to do. In the above we use a
list comprehension under the *assumption* that its elements are of the
form [S] for some S which is a string. It will fail silently if they
are not and skip the element. Also string:tokens/2 is under the
assumption there are no double occurrence of an @ character in the
string.


-- 
J.


More information about the erlang-questions mailing list