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??
Asked
Active
Viewed 1,093 times
0
-
Possible duplicate of [convert string to list in prolog](https://stackoverflow.com/questions/18224717/convert-string-to-list-in-prolog) – Anderson Green Feb 22 '18 at 03:13
2 Answers
0
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)

CapelliC
- 59,646
- 5
- 47
- 90
0
-
this is giving me folllowing error- `ԀERROR: main/0: Undefined procedure: split_string/4 Exception: (7) split_string([97, 46, 98, 46, 99, 46, 100], [46], [], _G1077) ?` – Nov 23 '14 at 07:33
-
1split_string works in SWI-Prolog version 7. instead ?- atomic_list_concat(L, ' ', 'How are you today ?'). – Ralff11 Nov 23 '14 at 07:56