【erlang】split from str

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-module(split).

-compile(export_all).

foo() -> 
	Topic = "/a/b/c/d/e/f/g/h",
	Test = splitTopic(Topic),
	io:format("===>final company is : ~p~n",[Test]).

splitTopic(Topic) -> 
    Keys = string:tokens(Topic, "/"),
    [Company, Dtype, Etype, Sid | Others] = Keys,
    io:format("~n~n===Split Topic===~n"),
    io:format("- Company = ~p~n- DeviceType = ~p~n- Event_type = ~p~n- Sid = ~p~n- Others = ~p~n~n", [Company, Dtype, Etype, Sid, Others]),
    rsplit(Company).

rsplit(Company) -> 
    Company.