Results 1 to 4 of 4

Thread: [Prolog] How to find a word in a string

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved [Prolog] How to find a word in a string

    Given an input in a string. Something like:

    Code:
    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?



    ØØ
    Last edited by NoteMe; Feb 28th, 2005 at 11:37 AM.

  2. #2
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: [Prolog] How to find a word in a string

    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?
    Merry Christmas

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [Prolog] How to find a word in a string

    Quote Originally Posted by JPicasso
    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:

    Code:
    %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.

  4. #4
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: [Prolog] How to find a word in a string

    Quote Originally Posted by NoteMe
    Hehehe...you are so cute......
    yeah, I get that a lot.
    Merry Christmas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width