nikdange_me
nikdange_me

Reputation: 3017

Check if string contain a char or not Erlang

I want to check if the string contains a specific character or alphanumeric number present in it.

Eg.

Line = "23423+e324AB".

What will be the best possible solution to find if the string 'Line' contains '+' symbol??

Thanks :)

Upvotes: 0

Views: 2768

Answers (1)

Maryna Shabalina
Maryna Shabalina

Reputation: 449

Probably, best is lists:member(hd("+"),"fff+fdd").

Time execution is fastes

9> timer:tc(fun() -> lists:member(hd("+"),"fff+fdd") end).
{11,true}
10> timer:tc(fun() -> string:str("ff+ggg", "+") > 0 end).
{1965,true}

Upvotes: 3

Related Questions