我在erlang中有这个变量Code,其值为"T00059"
我想从Code中提取这个值59
我尝试使用此代码提取此值"00059"
NewCode=string:substr(Code, 2, length(Code)),
Run Code Online (Sandbox Code Playgroud)
现在我想知道如何在第一个整数非空之前消除第一个零
意味着我们如何提取 "59"
例如,如果我有这个值"Z00887",我应该在最后这个值887
我在ubuntu 10.10工作,我使用erlang作为语言
我的目标是编写代码以便从erlang发送邮件
我试试这个代码:
-module(mailer).
-compile(export_all).
send(Destination, Subject, Body) ->
D = string:join(lists:map( fun(Addr) -> binary_to_list(Addr) end, Destination ), " " ),
S = io_lib:format("~p",[binary_to_list(Subject)]),
B = io_lib:format("~p",[binary_to_list(Body)]),
os:cmd("echo "" ++ B ++ "" | mail -s "" ++ S ++ "" " ++ D).
Run Code Online (Sandbox Code Playgroud)
并执行发送功能我尝试:
Erlang R13B03 (erts-5.7.4) [source] [rq:1] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
1> mailer:send([<<"testFrom@mail.com">>, <<"testto@yahoo.fr">>], <<"hello">>, <<"Hello guys">>..
"/bin/sh: mail: not found\n"
Run Code Online (Sandbox Code Playgroud)
如你所见,我有这个错误:
"/bin/sh: mail: not found\n"
Run Code Online (Sandbox Code Playgroud) 我用这种语法声明了Line变量:
Line ="1; nabil; chouaib; france; 27",
我想声明5个变量:Id,Firsname,lastname,address,age
Id应该包含1 Firsname应该包含nabil lastname应该包含chouaib地址应该包含france年龄应该包含27
所以我必须解析变量Line的内容
这种情况下的分离器是;
我有这个功能:
test()->
ForEachLine = fun(Line,Buffer)->
io:format("Line: ~s~n",Line),
[IdStr, FirstnameStr, LastnameStr, AddressTr, AgeStr] = string:tokens(Line, ";"),
Buffer end,
InitialBuffer = [],
csv:parse("/var/lib/mysql/test/person1.csv",ForEachLine,InitialBuffer).
Run Code Online (Sandbox Code Playgroud)
但是,当我执行测试功能T时出现此错误:
1> model:test().
Line: 1;nabil;chouaib;france;27
** exception error: no match of right hand side value [["1;nabil;chouaib;france;27"]]
in function model:'-test/0-fun-0-'/2
in call from csv:start_parsing/3
Run Code Online (Sandbox Code Playgroud)
问题与这一行有关:
[IdStr, Firstname, Lastname, Address, AgeStr] = string:tokens(Line, ";")
Run Code Online (Sandbox Code Playgroud)
我认为Line的类型不是一个字符串(但是在显示错误之前的consol中 Line: 1;nabil;chouaib;france;27)
所以我应该知道Line的类型
csv.erl模块是: …