PDA

Click to See Complete Forum and Search --> : [Prolog] How to find a word in a string


NoteMe
Feb 27th, 2005, 12:33 PM
Given an input in a string. Something like:


eliza :-
write('Hello'),nl,
read(sInput).



How can I find out if a certian word is in the sInput variable. So I can give feedback?



ии

JPicasso
Feb 28th, 2005, 09:11 AM
Huh?

VB6.0 has an instr function.

If this is another language, perhaps the specific-language forum would be a better place.

or is it language-specific?

NoteMe
Feb 28th, 2005, 09:15 AM
Huh?

VB6.0 has an instr function.

If this is another language, perhaps the specific-language forum would be a better place.

or is it language-specific?

Hehehe...you are so cute...:)...I added the language in [ ], Prolog it is called, and it looks nothing like VB...:(


Kedaman helped me on MSN. Here is the solution:


%example on how to run (at the moment..:))
%atom_chars('you are an idiot',A),atom_chars('an',B),search(A,B,C).



search2([_|_],[],1).
search2([X|XS],[X|YS],N):- search2(XS,YS,N).
search([X|XS],[X|YS],N):- search2(XS,YS,N).
search([_|XS],YS,N):- search(XS,YS,N1),N is N1+1.
search([],_,0):-!,fail.

JPicasso
Mar 2nd, 2005, 02:06 PM
Hehehe...you are so cute...:)...

yeah, I get that a lot.