A
A
Artemy Gast2018-03-01 18:49:18
C++ / C#
Artemy Gast, 2018-03-01 18:49:18

How to do string value validation in C# Console .txt file?

Searching for my question in the expanses of the world's garbage, I did not find anything, I would like to ask you, geniuses, how, how to check for the presence of a question and answer, for example, you write "Hello" to the bot, it looks for this value in the file, and if it finds then it gives the answer "Hello", and if not, it asks the user to enter the value that he will give on the next call, who could help the wanderer of the vastness of the network, is there really no answer to my question, just in case my script is:

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace MyNeuBot
{
  public class Neuron
  {
    static string st;
    static string path = @"C:\Users\HEJlbCOH\Desktop\t.txt";
    List<string> stels = new List<string>();


    public void Teach()
    {
      stels.Add(st);
      File.WriteAllLines(path, stels.ToArray());
    }
    static string Ans(string q)
    {
      st = q;
      q = st;
      string ans = " ";

      q = q.ToLower();

      string[] baza = File.ReadAllLines(path);

      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

1 answer(s)
R
Roman Mirilaczvili, 2018-03-09
@2ord

Probably such a bot should work with some DBMS and with new words it will replenish its vocabulary.
To get started, you can take a CSV file as a DBMS (the easiest option) and connect to it as described in https://www.codeproject.com/Questions/147298/conne...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question