Converting a user input string to list

1.1k Views Asked by At

Is there any way in which I can convert a string to list separated by spaces.The string has to be entered by the user. Suppose How are you today ? is the string entered by the user,I want to store it in a list say L, L=['How','are','you','today','?']. How can I do this??

2

There are 2 best solutions below

2
On BEST ANSWER

?- split_string("How are you today ?", " ", "", L).

per this site.

0
On

SWI-Prolog offers tokenize_atom

?- [library(porter_stem)].
?- tokenize_atom('How are you today ?', L).
L = ['How', are, you, today, ?].

note that quoting atoms is necessary only when the lexical representation aliases some other type (notably variables)