A
A
Artemy Gast2018-02-28 20:27:19
C++ / C#
Artemy Gast, 2018-02-28 20:27:19

How to write commands and responses to a file and play it on C# Console?

Hello toasters, I have a question, I’m making a chat bot for personal use and I can’t understand how I can save the command and the answer to it that the user will have to enter, I know about the System.IO library; and I know about its functions, but it doesn’t cross my mind how to implement it, an example of what I want:
Human: Hello
Bot: I don’t know this, enter the word that I will have to answer when entering this
Human: Hello
Here is saving the command and response to a file, and the next time you enter it, it will give the answer
Man: Hello
Bot: Hello
Who is not difficult to help please :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bashinsky, 2018-02-28
@HEJlbCOH

You get the person's answer and save it to a file.
There are many options, but I will list 2:
1) (This is the right approach) You have a Dictionary, List> (collections of questions and answers to them).
When you receive an unknown question, you ask how to answer it and then write this pair in the collection after checking if there is a similar answer there (maybe the question is new, but the answer is already in the collection, for example: hello / hello, etc., and the answer will do the same) and after each serialization change
, you dump this Dictionary into a json file.
I don't want to offend or anything like that, but judging by the fact that such a question arose, this option will be difficult for you.
2) (Simple) question=answer
for each new question and when you receive an answer to it, write it to the file "question = answer"
File.ReadAllText("questions.txt"); you can read it like this, but you still need the ability to parse :)
and there is also an option to use ini

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question