Leo_D
Leo_D

Reputation: 27

How to read from text file and add into an array?

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?

Upvotes: 0

Views: 493

Answers (1)

Skye MacMaster
Skye MacMaster

Reputation: 914

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

Upvotes: 1

Related Questions