protected override void Add(string fileName) { string contents = File.ReadAllText(fileName); int position = 0; while ((position = contents.IndexOf("\"x\"", position) + 3) != 2) { int id = contents.IndexOf("\"id\"", position) + 4; int text = contents.IndexOf("\"text\"", position) + 6; int choices = contents.IndexOf("\"choices\"", position) + 9; if (id == 3 || text == 5 || choices == 8) { continue; } id = contents.IndexOf(':', id) + 1; Question imported = new Question { ID = int.Parse(contents.Substring(id, contents.IndexOf(',', id) - id).Trim()), Text = Parsing.GetTextEntry(ref contents, contents.IndexOf(':', text) + 1) }; choices = contents.IndexOf('[', choices) + 1; int correct = contents.IndexOf("\"correct\"", choices); for (int answer = 1; answer <= 4; ++answer) { choices = contents.IndexOf('{', choices) + 1; if (choices <= correct) { imported.Correct = answer; } imported[answer] = Parsing.GetTextEntry(ref contents, contents.IndexOf("\"text\"", choices) + 6); choices = contents.IndexOf('}', choices) + 1; } Add(imported); } }
protected override void Add(string fileName) { string contents = File.ReadAllText(fileName); int position = 0; while ((position = contents.IndexOf("\"x\"", position) + 3) != 2) { int id = contents.IndexOf("\"id\"", position) + 4; int category = contents.IndexOf("\"category\"", position) + 10; if (id == 3 || category == 9) { continue; } id = contents.IndexOf(':', id) + 1; WorstResponse imported = new WorstResponse(int.Parse(contents.Substring(id, contents.IndexOf(',', id) - id).Trim()), Parsing.GetTextEntry(ref contents, contents.IndexOf(':', category) + 1)); Add(imported); } }
protected override void Add(string fileName) { string contents = File.ReadAllText(fileName); int position = 0; while ((position = contents.IndexOf("\"x\"", position) + 3) != 2) { int id = contents.IndexOf("\"id\"", position) + 4; int text = contents.IndexOf("\"text\"", position) + 6; int choices = contents.IndexOf("\"choices\"", position) + 9; if (id == 3 || text == 5 || choices == 8) { continue; } id = contents.IndexOf(':', id) + 1; FinalRounder imported = new FinalRounder(int.Parse(contents.Substring(id, contents.IndexOf(',', id) - id).Trim()), Parsing.GetTextEntry(ref contents, contents.IndexOf(':', text) + 1)); choices = contents.IndexOf('[', choices); position = Parsing.FindArrayEnd(ref contents, choices); string choiceCut = contents.Substring(choices + 1, position - choices - 2); choices = 0; while (true) { int correct = choiceCut.IndexOf("\"correct\"", choices) + 9; text = choiceCut.IndexOf("\"text\"", choices) + 6; if (correct == 8 || text == 5) { break; } string correctResult = choiceCut.Substring(correct, text - correct - 6); imported.Items.Add(new FinalRounderChoice(correctResult.Contains("true"), Parsing.GetTextEntry(ref choiceCut, choices = choiceCut.IndexOf(':', text) + 1))); } Add(imported); } }