我有一个清单
["user2","user","user4"]
我想转换成这样的字符串:
2> "('user2','user','user4')".
"('user2','user','user4')"
我怎样才能做到这一点?
答案 0 :(得分:1)
这是使用列表推导将单引号添加到开头和结尾的一种方式,然后string:join/2
将它们与逗号分隔符连接起来:
1> ["'" ++ X ++ "'" || X <- ["user2","user","user4"]].
["'user2'","'user'","'user4'"]
2> string:join(["'" ++ X ++ "'" || X <- ["user2","user","user4"]], ",").
"'user2','user','user4'"
3> "(" ++ string:join(["'" ++ X ++ "'" || X <- ["user2","user","user4"]], ",") ++ ")".
"('user2','user','user4')"