【发布时间】:2019-02-06 15:00:46
【问题描述】:
我是 Erlang 的新手。我只想为字符串变量重新赋值:
get_alert_body(Packet) ->
BodyElement = element(8,Packet),
Body = "my text",
Els = xmpp:get_els(Packet),
lists:foreach(fun(El) ->
ElementName = io_lib:format("~s",[xmpp:get_name(El)]),
IsFile = string:equal(ElementName,"fileType"),
if
IsFile ->
FileType = fxml:get_tag_cdata(El),
IsPhoto = string:equal(FileType,"photo"),
IsVideo = string:equal(FileType,"video"),
if
IsPhoto ->
%% if it gets to this I would like to return "my photo"
Body = "my photo";
IsVideo ->
%% else if it gets to this I would like to return "my video"
Body = "my video";
true ->
%% otherwise I would like to return "my text"
ok
end;
true ->
ok
end
end, Els),
Body.
但我收到此错误:
error,{badmatch,"test2"}
即使我做了类似的事情:
A = "test1",
A = "test2",
我得到同样的错误。
感谢您的帮助。
【问题讨论】: