`
jiorry
  • 浏览: 276588 次
  • 性别: Icon_minigender_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边更新,不写不更新...

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics