Siri-like Program Help
Author |
Message |
DaBigOne
|
Posted: Wed Dec 04, 2013 5:47 pm Post subject: Siri-like Program Help |
|
|
What is it you are trying to achieve?
Trying to make a Siri-like program which can detect a specific word in a string, and return an appropriate result.
What is the problem you are having?
I can make Turing search for the string and detect whether it is there, but I don?t know how to add an if command to this, so if it detects a specific word, it will do a specific action.
Describe what you have tried to solve this problem
I?ve tried adding an if command to the index, but it gives me an error.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var weather : string := "weather"
var phrase : string
put "Hello. How can I help you?"
get phrase : *
put "You asked for weather at: ",
index (phrase, weather )
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Wed Dec 04, 2013 10:48 pm Post subject: RE:Siri-like Program Help |
|
|
Ok, all index does is return a number for you. If it is in the string, it returns the position of the pattern inside the string. If it's not in the string, it will return zero. Eg index("hello", "el") returns 2, but index("hello", "a") returns zero. So you can do something like this:
if index(input, stringYoureLookingFor) > 0 then
do something
end if |
|
|
|
|
![](images/spacer.gif) |
DaBigOne
|
Posted: Wed Dec 04, 2013 11:13 pm Post subject: Re: Siri-like Program Help |
|
|
Ah, the solution seems so obvious now.
Thank you ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu Dec 05, 2013 12:13 am Post subject: RE:Siri-like Program Help |
|
|
anytime (Y) |
|
|
|
|
![](images/spacer.gif) |
|
|