chat bot in C#

3063896c06829a58387478e663317a3a
0
Alex007152 101 Aug 29, 2006 at 15:45

Hi i’m developing a chatbot in C#. I have a string variable for the user input (the chatbot is a console application) and i want to tell the robot to read basicaly just a part of what the user entered. for instance:

Console.WriteLine("Hello!");
            string userInput;
            userInput = Console.ReadLine();
            if (userInput = "noob ----") //the ---- part is input that the bot ignores
                                     //The bot only reacts at the 'noob' part of the input
            {
                Console.WriteLine("You can't just call me a noob!");
            }

7 Replies

Please log in or register to post a reply.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Aug 29, 2006 at 16:18

Do you simply want to check whether the input contains a specified word, or do you want to specify surrounding tokens? In case you want to simply check for keywords:

string s;
if (s.contains(“noob”))
{
//…
}

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Aug 29, 2006 at 16:19

You might want to investigate Regular Expressions for more sophisticated text processing.

3063896c06829a58387478e663317a3a
0
Alex007152 101 Aug 29, 2006 at 17:05

@roel

Do you simply want to check whether the input contains a specified word, or do you want to specify surrounding tokens? In case you want to simply check for keywords: string s;
if (s.contains(“noob”))
{
//…
}

I had this error when i tried it:

'string' does not contain a definition for 'contains'

:/
@Reedbeta

You might want to investigate Regular Expressions for more sophisticated text processing.

I’ll have a look, thanks for the link :)

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Aug 29, 2006 at 17:43

@Alex007152

I had this error when i tried it:

'string' does not contain a definition for 'contains'

:/

It should have been “Contains”. Come on, develop some `zelfredzaamheid’ (wow, that word looks scary between english words), or do you rather want to spend your whole life on forums asking trivial questions and being dependent on other people?

Another keyword for sophisticated parsing is Backus-Naur Form (BNF). But that depends on what you consider sophisticated.

3063896c06829a58387478e663317a3a
0
Alex007152 101 Aug 29, 2006 at 19:05

@roel

It should have been “Contains”. Come on, develop some `zelfredzaamheid’ (wow, that word looks scary between english words), or do you rather want to spend your whole life on forums asking trivial questions and being dependent on other people? Another keyword for sophisticated parsing is Backus-Naur Form (BNF). But that depends on what you consider sophisticated.

Look, im new to C# and the fact that i’m not a proffesional programmer and the fact that many books i purchase lead me to errors that go beyond my knowledge brings me here. I’m doing my best to learn as much as possible from other people and especially good written books. You can’t learn things without help of others but– being too much dependent on others is not good either. I’m sorry for bothering everyone with my noob questions…

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Aug 29, 2006 at 19:29

What roel means is that when you come up against an error like that, you ought to do a search in the MSDN or some other documentation to find the actual function being referred to. Reference material should always be your first stop when you encounter an error - then, if you’ve looked up everything you can think of and still can’t figure it out, ask someone.

406ad7b52f4ed7443e3971e6b2adf430
0
kariem2k 101 Aug 29, 2006 at 20:36

Hi
First of all it is “Contains” not “contains”,C# is case-sensitive.

But i am using more restrictive method,Also a bit faster :) :

/*it takes the first 9 chars from userinput string and do case-sensitve comparison with "noob ----"*/

if(userInput.Substring(0,9) == "noob ----")
   do something.........

Don’t forget comparison in c# & c++ is done with “==” not “=”,in c# the compiler will complain but in c++ the condition will be always true and will cause many troubles at run-time.

You must learn how to teach yourself and specially how to seek information from MSDN library.