Skip to content

AIQUestionbank #5

Description

@tranlongcbvn112-sketch

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;

public static class AIQuestionBank
{
public static List Questions { get; private set; } = new List();
private static string filePath = "AIQuestions.txt";

public static void LoadFromFile()
{
    try
    {
        if (!File.Exists(filePath))
        {
            
            File.WriteAllText(filePath, "");
            Questions.Clear();
            return;
        }

        string[] lines = File.ReadAllLines(filePath);
        Questions.Clear();

        string buffer = "";
        foreach (var line in lines)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                if (!string.IsNullOrWhiteSpace(buffer))
                {
                    Questions.Add(buffer.Trim());
                    buffer = "";
                }
            }
            else
            {
                buffer += line + "\n";
            }
        }

        if (!string.IsNullOrWhiteSpace(buffer))
            Questions.Add(buffer.Trim());
    }
    catch (Exception ex)
    {
        MessageBox.Show($"❌ Error loading AIQuestions.txt: {ex.Message}");
    }
}





/// <param name="questionEntry"></param>
public static void AddToBank(string questionEntry)
{
    Questions.Add(questionEntry.Trim());
    
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions