首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

erlang 技艺备忘

2012-10-06 
erlang 技巧备忘1. 左补齐 padding leftio:format(~4..Ts~n, [a]).? - TTTaio:format(~4..0B~n, [1

erlang 技巧备忘

1. 左补齐 padding left

io:format("~4..Ts~n", ["a"]).? -> TTTa

io:format("~4..0B~n", [1]).? -> 0001

?

文档里介绍的具体语法:The general format of a control sequence is ~F.P.PadModC .

F:长度???

P:保留小数位数???

Pad:补齐的字符串?

Mod:模式,即,~s|~w|~B??

C:The character C determines the type of control sequence to be used. 还理解的不是很清楚

FP为任意数字

?

2. io:format | io_lib:format

io:format("~4..0B~n", [1])??????? -> 0001?? 默认直接写入当前的输出流

io_lib:format("~4..0B~n", [1])? -> [["000", "a"], "\n"] 返回了一个字符串列表

?

3. {ok, Columns, _Rows=[R]} = db:find(Sql).

其中的_Rows 为占位变量,只是标识一下变量的意义。_Rows=[R] 标识和赋值一并完成。

?

4. 得到当前时间的字符串

{Year, Mon, Day} = date(),
?{Hour, Min, Sec} = time(),

io_lib:format("~B-~2..0B-~2..0B ~2..0B:~2..0B:~2..0B", [Year, Mon, Day, Hour, Min, Sec]).

?

5. 字符串转换成整数

string_to_int(Bin) when is_binary(Bin) ->
???? string_to_int(binary_to_list(Bin));
string_to_int(Str) when is_list(Str) ->
???? {I, []} = string:to_integer(Str),
???? I.

?

6. aes 加密

crypto:aes_cfb_128_encrypt(Key, IVec , Text )

crypto:aes_cfb_128_decrypt(Key, IVec , Text )

?

文档:Text must be a multiple of 128 bits (16 bytes). Key is the AES key, and IVec is an arbitrary initializing vector. The lengths of Key and IVec must be 128 bits (16 bytes).

Key,IVec必须为128bits, Text必须为128bit的倍数,不足的话补足。呵呵,不仔细看的话,会被折磨的。

??

边写erlang边更新,不写不更新...

热点排行