Vlad Otrocol
Vlad Otrocol

Reputation: 3180

Split string in items

I have a string

'a, b, c'

What is the easiest way to split this into items?

[a,b,c]

Upvotes: 1

Views: 2064

Answers (2)

Vlad Otrocol
Vlad Otrocol

Reputation: 3180

I used this in the end

atomic_list_concat(L,', ', 'a, b, c').

L=['a','b','c']

Upvotes: 1

gusbro
gusbro

Reputation: 22585

Asumming you have a string (represented by an atom), you can write a procedure atoms_list/2:

atoms_list(Atom, List):-
  atomic_list_concat(['[', Atom, ']'], NAtom), 
  term_to_atom(List, NAtom).

Example:

?- atoms_list('a,b,c', List).
List = [a, b, c].

Upvotes: 1

Related Questions