Answer the question
In order to leave comments, you need to log in
How to link chatbot code to database in C#?
Hello. I am writing a simple chat bot in Visual Studio in C#. How to link the code to the database? Folder path to the notepad text file "C://Users//Larisa//Desktop//Photos and documents//Mathematics and info//C#//1.txt". File (1.txt) in the same folder as the code. In a notebook, several phrases are written in a column: hello, hello, how are you, good. The bot only responds to hello. I don't know how to make a database.
using System;
using System.IO;
namespace Chat
{
class Program
{
static string Trim(string str, char[] chars)
{
string strA = str;
for (int i = 0; i < chars.Length; i++)
{
strA = strA.Replace(char.ToString(chars[i]), "");
}
return strA;
}
static string Ans(string q)
{
string tr = ")(:^^=!?, ",
ans = "";
q = q.ToLower();
q = Trim(q, tr.ToCharArray());
string[] baza = File.ReadAllLines("C://Users//Лариса//Desktop//Фото и документы//Математика и инфа//C#//1.txt");
for (int i = 0; i < baza.Length; i += 2)
{
if (q == baza[i])
{
ans = baza[i + 1];
break;
}
}
return ans;
}
public static void Main()
{
while (true)
{
Console.Write("Ваш вопрос: ");
string q = Console.ReadLine();
Console.WriteLine("Бот сказал: " + Ans(q) + "\n");
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question