Beispiel #1
0
        // Reading kanji words form a text file. The text file has a specific format
        private void readWords()
        {
            string kanjiPath = @"data\kanji.txt";

            StreamReader reader;
            string       line;

            // Hiragana reading
            reader = new StreamReader(kanjiPath);
            while ((line = reader.ReadLine()) != null)
            {
                // Author Ahmad Mageed
                // From here ***
                var delimiters = new List <string> {
                    "#k#", "#f#", "#r#", "#m#", "#e#"
                };
                string pattern = "(" + String.Join("|", delimiters.Select(d => Regex.Escape(d))
                                                   .ToArray())
                                 + ")";

                string[] result = Regex.Split(line, pattern);
                // To here ***

                KanjiWord kanjiWord    = new KanjiWord();
                int       stringLength = result.Length;

                for (int index = 0; index < stringLength; index++)
                {
                    switch (result[index])
                    {
                    case "#k#":
                        kanjiWord.setKanji(result[index + 1]);
                        index++;
                        break;

                    case "#f#":
                        kanjiWord.setFurigana(result[index + 1]);
                        index++;
                        break;

                    case "#r#":
                        kanjiWord.setRomaji(result[index + 1]);
                        index++;
                        break;

                    case "#m#":
                        kanjiWord.setEnglish(result[index + 1]);
                        index++;
                        break;

                    case "#e#":
                        break;
                    }
                }
                kanji.Add(kanjiWord);
            }
            reader.Close();
        }
Beispiel #2
0
        private void saveWord_Click_1(object sender, EventArgs e)
        {
            KanjiWord newWord = new KanjiWord();

            newWord.setKanji(kanjiBox.Text);
            newWord.setFurigana(furiganaBox.Text);
            newWord.setRomaji(romajiBox.Text);
            newWord.setEnglish(englishBox.Text);

            kanji.addWord(newWord);
        }