erlang字符串分割
来源:互联网 发布:网络婚姻介绍所 编辑:程序博客网 时间:2024/06/05 05:00
先上代码:
split(L, Splitters) -> string:tokens(L, Splitters).split2(L, Splitters) -> case lists:any(fun(A) -> string:str(L,[A]) > 0 end, Splitters) of true -> [H|_] = split(L, Splitters), T = string:substr(L,string:len(H)+2), case length(T) of 0 ->[H]; _ ->[H,T] end;_ -> [L] end.splitn(L, Splitters, N) -> splitn(L, Splitters, N, []).splitn([], Splitters, N, NL) -> NNL = lists:concat([[],NL]), lists:reverse(NNL);splitn(L, Splitters, 1, NL) -> [H|T] = split2(L, Splitters), NNL = lists:reverse(NL), case length(T) of0 -> lists:concat([NNL, [H]]);_ -> NT = lists:concat([T]), lists:concat([NNL, [H], NT]) end;splitn(L, Splitters, N, NL) -> [H|[T]] = split2(L, Splitters), splitn(T, Splitters, N-1, [H|NL]).
测试用例:
split_test(_Config) -> A1 = "firstname", A2 = "secondname", A = string:join([A1, A2], ":"), B1 = "info1_1", B2 = "info1_2", B = string:join([B1, B2], ":"), C = "info2", D = "info3", E = "info4", F = "info5", G = "info6", List = string:join([A, B, C, D, E, F, G], ";"), [A,B,C,D,E,F,G] = mr_util:split(List, ";"), L1 = string:join([B,C,D,E,F,G],";"), [A,L1] = mr_util:split2(List, ";"), L2 = string:join([A2,B,C,D,E,F,G],";"), [A1,L2] = mr_util:split2(List, ";:"), L3 = string:join([C,D,E,F,G], ";"), [A,B,L3] = mr_util:splitn(List, ";", 2), L4 = string:join([D,E,F,G], ";"), [A,B,C,L4] = mr_util:splitn(List, ";", 3), L5 = string:join([B,C,D,E,F,G], ";"), [A1,A2,L5] = mr_util:splitn(List, ";:", 2), L6 = string:join([B2,C,D,E,F,G], ";"), [A1,A2,B1,L6] = mr_util:splitn(List, ";:", 3), ok.
- erlang字符串分割
- erlang 用分号分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 分割字符串
- 字符串分割
- 关于字符集
- android窗口管理机制
- linux(2)
- SliTaz不能启动到图形界面
- 外键上建立索引的好处
- erlang字符串分割
- NotOnlySuccess 的【完全版】线段树
- html5本地存储对象
- Asymmetric VLAN学习
- "ping: unknown host www.baidu.com" 解决方法
- Apache Shiro 加密管理
- oracle中v$database视图详解
- git使用指南
- 太弱的愿望 = 没有愿望