Hey
I had made a chatbox, where if it don't know to the question, it just spit random sentence that don't make sense, but i don't how to make it read the question and se if it has a answer for it, and if it don't have a answer it should spit the one of the random sentence out...
How do i make it do that.??

Can you be so kind to post here the chat part you have written so far where you want to include the search function?

Yes of course

string[] svin = { "Noob Error", "Jeg skal lige have en joint", "Der er rygepause", "Jeg skal lige lave pølle", "Har ikke tid til dit lort", "Kællingen skal lige kneppes", "Hvad snakker du om?", " Skal du ha' slag?", "Min luder er lige kommet", "Du er dum i dit ansigt", "Du er dum og høre på", "Få dig et liv" };
            Random Rand = new Random();
 while (tændt)
            {
                Console.WriteLine("Spørg Jesus hvad du vil vide?");
                Console.Write(">");
                sætning = Console.ReadLine();

It is in danish.
When the bot don't know what "sætning" is, then it have to spit one of the random sentence out..

Lets separate the problem in parts:
1) Find the returned phrase in a list of known ones
2) Return a random string from svin if the searched phrase does not exists

Lets assume that we already have a list of known prhases like

static string[] knownPhrases = {"You are the best","Can you help me?"}
static string[] knownAnswers = {"You are rightr","Of course"}
static string[] svin = { "Noob Error", "Jeg skal lige have en joint", "Der er rygepause", "Jeg skal lige lave pølle", "Har ikke tid til dit lort", "Kællingen skal lige kneppes", "Hvad snakker du om?", " Skal du ha' slag?", "Min luder er lige kommet", "Du er dum i dit ansigt", "Du er dum og høre på", "Få dig et liv" };

In order to find if the phrase is know or not you can create a function that will return the righ answer or a random one like:

static string GetAnAnswer(string inputPhrase)
{
for (int i=0;i<knownPhrases.Length;i++) if (inputPhrase == knownPhrases[i]) return knownAnswers[i];

Random rand = new Random();
// this will return a non negative value less tha the max supplied
int randvalue = (int) rand.Next(svin.Length); 

return svin[randvalue];
}

Then after reading the input phrase you can :

if (sætning.Length==0) return; // end of 
Console.WriteLine(GetAnAnswer(sætning));

Hope this helps

If this solved your question, please mark this thread as solved.

Thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.