It is unclear what you mean by string. But since you say that you convert it to a list, you can mean atoms. For this purpose, ISO Prolog offers atom_concat/3 and sub_atom/5 .
| ?- atom_concat(X,Y,'abc'). X = '', Y = abc ; X = a, Y = bc ; X = ab, Y = c ; X = abc, Y = ''. | ?- sub_atom('abcbcbe',Before,Length,After,'bcb'). Before = 1, Length = 3, After = 3 ; Before = 3, Length = 3, After = 1.
Otherwise use DCG! Here is how
seq([]) --> []. seq([E|Es]) --> [E], seq(Es). ... --> [] | [_], ... . subseq([]) --> []. subseq(Es) --> [_], subseq(Es). subseq([E|Es]) --> [E], subseq(Es). seq_substring(S, Sub) :- phrase((...,seq(Sub),...),S). seq_subseq(S, Sub) :- phrase(subseq(Sub),S).
Confirmations
The first appearance of the above definition ... on p. 205, note 1 to
David B. Searls, "Learning DNA Linguistics with a Specific Sentence Grammar." NAKLP 1989, Volume 1.