Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String splitting problems in Erlang

Tags:

erlang

I've been playing around with the splitting of atoms and have a problem with strings. The input data will always be an atom that consists of some letters and then some numbers, for instance ms444, r64 or min1. Since the function lists:splitwith/2 takes a list the atom is first converted into a list:

24> lists:splitwith(fun (C) -> is_atom(C) end, [m,s,4,4,4]).
{[m,s],[4,4,4]}
25> lists:splitwith(fun (C) -> is_atom(C) end, atom_to_list(ms444)).
{[],"ms444"}
26> atom_to_list(ms444).
"ms444"

I want to separate the letters from the numbers and I've succeeded in doing that when using a list, but since I start out with an atom I get a "string" as result to put into my splitwith function...

Is it interpreting each item in the list as a string or what is going on?

like image 298
Fylke Avatar asked Mar 28 '26 09:03

Fylke


1 Answers

You might want to have a look at the string module documentation:

http://www.erlang.org/doc/man/string.html

The following function might interest you:

tokens(String, SeparatorList) -> Tokens
like image 66
Roberto Aloi Avatar answered Apr 01 '26 08:04

Roberto Aloi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!