1

I am currently working on a application which will give flash card like questions which I have stored on the system. I was wondering what would be my best option to store lists of information. The formatting I am currently using is where the first line is the question, next line is the correct answer and all subsequent lines are distractors, this being accomplished through file.read and write. The problem I have with this is that I cant use special symbols, like say I wanted to write NH4+, I would have to write it as NH4+.

So far I have looked into SQL lite and JSON, but neither seam to work, any advice is appreciated.

I cant seam to get txt files to properly return Unicode values and they feel almost clunky to use. with that I am unsure how to get Winforms to read and properly display Unicode either

collent
  • 13
  • 2
  • 2
    A text file can contain whatever you put in it, in whatever encoding you want. Even Notepad lets you choose the encoding you want (it's right beside the `[Save]` button in the Save As dialog). Then, when you read from the text file, you need to pick the right encoding. In SQL (not sure about SQL lite), you can store UTF-16 in NChar/NVarChar columns, or, you can store UTF-8 in Char/VarChar columns. You reallly need to write some code, and show us what issues you are having. Your question, as written will likely close soon - it's not a very good StackOverflow question – Flydog57 Sep 09 '22 at 17:05
  • 1
    If Unicode characters aren't rendering in your application, look for a font that has a reasonably full character set. Not all fonts can render all Unicode characters (there are a lot of them) – Flydog57 Sep 09 '22 at 17:07
  • 1
    [How to display text with subscripts or superscripts in the Title Bar?](https://stackoverflow.com/a/59441301/7444103) -- JSON and UTF-8 are fine as file storage, otherwise, the previous comments (or just store the bytes). – Jimi Sep 09 '22 at 17:17
  • Would you be willing to consider storing and displaying html. You can still do it with winforms. – tgolisch Sep 09 '22 at 17:19

1 Answers1

1
  1. Create a new Windows Forms app.
  2. Add a new item (JSON) named "text.json"
    • Set it's "Copy to Output Directory" property to "Copy Always"
  3. Add the following to the file (typing this is the hardest part)
{
  "fractions": [
    "2½",
    "4¾"
  ],
  "chemistry": [
    "NH₄",
    "H₂SO₄",
    "³He"
  ],
  "cards": [
    "A♠",
    "2♥",
    "10♢",
    "J♧"
  ]
}
  1. Add two multiline text boxes to the form (they'll be named textBox1 and textBox2 by default)
  2. Double-click the Caption (title area) of the form in the designer, this will bring up a wired up Load handler for the form
  3. Paste this in as the body of the Load handler:
private void Form1_Load(object sender, EventArgs e)
{
    var json = File.ReadAllText("text.json");
    textBox1.Text = json;
    var data = JsonConvert.DeserializeObject<Dictionary<string, string[]>>(json);
    var buffer = new StringBuilder();
    foreach (var topLevel in data)
    {
        buffer.AppendLine(topLevel.Key);
        foreach (var item in topLevel.Value)
        {
            buffer.AppendLine($"    {item}");
        }
    }
    textBox2.Text = buffer.ToString();
}
  1. Run the program. You will get this in textBox1:
{
  "fractions": [
    "2½",
    "4¾"
  ],
  "chemistry": [
    "NH₄",
    "H₂SO₄",
    "³He"
  ],
  "cards": [
    "A♠",
    "2♥",
    "10♢",
    "J♧"
  ]
}
  1. And this in textBox2
fractions
    2½
    4¾
chemistry
    NH₄
    H₂SO₄
    ³He
cards
    A♠
    2♥
    10♢
    J♧

Is your issue more complicated than this? This worked the first time - I did no magic to get it to Just Work

Flydog57
  • 6,851
  • 2
  • 17
  • 18