[erlang-questions] problem with string:tokens

Ulf Wiger <>
Tue Jun 30 23:02:11 CEST 2009


info wrote:
> Hi All,
> 
> I have two strings: S1="A,,C,D" and S2="A,B,,D"
> 
> I do string:tokens(S1) :  "A","C","D"  length =3 I do
> string:tokens(S2) :  "A","B","D"  length = 3
> 
> Imagine the string S = S1 or S2 How can I know if B is absent or C ?
> 
> It is a general question of course ! the tokens function cannot
> separate the tokens with a composite string unfortunately (here ",,")

Perhaps if you use the re module instead:

64> string:tokens("A,,C,D", ",").
["A","C","D"]
65> re:split("A,,C,D",",").
[<<"A">>,<<>>,<<"C">>,<<"D">>]

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd
http://www.erlang-consulting.com


More information about the erlang-questions mailing list