0

I am currently creating a quiz and am trying to get the data in my text file to be read using a quiz but I have hit a stumbling block in seeing how to get it to display the data ?

My Folder :

Windows.Storage.StorageFolder QuestionsFolder =
    Windows.Storage.ApplicationData.Current.LocalFolder;

My Array :

String[] Questions = new String[10];

My Read Questions async function :

async Task ReadQuestions()
{
    try
    {
        StorageFile sampleFile = await QuestionsFolder.GetFileAsync("ms-appx:///Assets/Questions/myFile.txt");
        String Questions = await FileIO.ReadTextAsync(sampleFile);

        // Data is contained
    }
    catch (Exception)
    {

    }
}

Sample Data:

"questions_id","questions" 
1,"What is the correct element for Gold ?"
2,"What is the correct element for Hydrogen?"
3,"What is the correct element for Oxygen?

Any ideas on how to complete this so that it loads the questions from the text file and into the array?

10
  • 3
    We'd need to know how the file is formatted. You'd also be MUCH better off using a List<string> instead of array. Commented May 8, 2015 at 16:55
  • Hi I am just using a the .txt format and would it be easier to get the data from the file to add into the List<string> than using an array ? Commented May 8, 2015 at 16:58
  • 1
    Yes, but what is the text that you're storing? You're not telling us how it can be split to go into different "slots" of the collection. A List is better than an array because the length is dynamic. If you have an 11th object to store in your array, your current program will blow up. Commented May 8, 2015 at 16:59
  • krillgar's question is what is in the text file. Is it just the text of questions? Is there other information like question IDs, etc? Commented May 8, 2015 at 17:00
  • Oh right ok sorry I thought he meant what was the file type, there are two fields which is id and questions with an example 1, "QuestionTest" Commented May 8, 2015 at 17:01

1 Answer 1

1

string[] questions = File.ReadAllLines("ms-appx:///Assets/Questions/myFile.txt");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.