从转换为erlang中的字符串形式的列表中提取元素

Extracting elements from list converted into string form in erlang

我在 mnesia database.Which 中有一个 group_info_db table 包含关于 group.Its 属性的数据是 groupId,Grouptype,GroupName,xxx,xxx,members.This 成员属性包含字符串形式的所有成员的名称(Ex-"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,")。我获取了所有对应于 [=18 的组=] 有时一个成员与许多组关联,因此从 db.Like

获取大量数据
  [{group_info_db,"12err1","0","Atif_aslam2","+111@devlab","+111@devlab","+1@devlab,    +1111@devlab,+919470220061@devlab,+111@devlab,"},
{group_info_db,"GroupID12","1","GroupName12","+3@devlab","+3@devlab",
"+1@devlab,+2@devlab,+3@devlab,+918800869860@devlab,+3@devlab,"},
{group_info_db,"VVv","Viv_12345","0","+111@devlab","+111@devlab",
"+1@devlab,+11@devlab,+111@devlab,"},
{group_info_db,"VVV5","0","Atif_aslam2","+111@devlab","+111@devlab",
"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,"},
{group_info_db,"VVV6","0","Atif_aslam2","+111@devlab","+111@devlab",
"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,"},
{group_info_db,"GroupID","GroupName","GroupType","+3@devlab","+3@devlab",
"+1@devlab,+2@devlab,+3@devlab,+3@devlab,"},
{group_info_db,"12err","0","Viv123","+111@devlab","+111@devlab",
"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,"},
{group_info_db,"12er","0","At","+111@devlab","+111@devlab",
"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,"},
{group_info_db,"12e","0","Vi123","+111@devlab","+111@devlab",
"+1@devlab,+1111@devlab,+919470220061@devlab,+111@devlab,"}]

我的问题是我还需要该组与此 Fetched data.I 相关联的组的所有 ID(第一个属性)data.I 将此 Fetched 数据转换为字符串 a 然后尝试解析它以获取所有groupids ,但那是很长 method.Any 其他想法?

最简单的方法可能只是向下移动组列表并获取每个组元组的第二个元素:

get_group_id([Group|Groups]) ->
    [element(2, Group)|get_group_id(Groups)];
get_group_id([]) -> [].

看到每个组元组都有:

{group_info_db,GroupId,GroupType,GroupName,AdminId,CreatorId,Members}

您也可以直接使用模式匹配编写函数:

get_group_id([{group_info_db,GroupId,_,_,_,_,_}|Groups]) ->
    [GroupId|get_group_id(Groups)];
get_group_id([]) -> [].

或使用列表:map/2 函数:

get_group_id(Groups) ->
    lists:map(fun ({group_info_db,GroupId,_,_,_,_,_}) -> GroupId end, Groups).

如果不是将成员生成为一个长字符串,而是生成一个成员名称字符串列表,那么使用起来会容易得多。这样组信息将变为:

{group_info_id,"12err1","0","Atif_aslam2","+111@devlab","+111@devlab",
 ["+1@devlab","+1111@devlab","+919470220061@devlab","+111@devlab"]}

这是什么类型的信息?