0

I am trying to read a text file by and extract the words from individual line to process. I am not too sure how to use the streamreader to read and process the text.

private async void readFile()
    {
        StorageFolder externalDevices = KnownFolders.RemovableDevices;
        IReadOnlyList<StorageFolder> externalDrives = await externalDevices.GetFoldersAsync();
        StorageFolder usbStorage = externalDrives[0];

        StorageFolder Folder = await usbStorage.CreateFolderAsync(FolderName, CreationCollisionOption.OpenIfExists);
        await usbStorage.GetFolderAsync(FolderName);
        IReadOnlyList<StorageFile> FileList = await Folder.GetFilesAsync();


        foreach (StorageFile file in FileList)
        {

            string Text = await FileIO.ReadTextAsync(file);
            //StreamReader Text = new StreamReader(file);
            //I am not sure how to implement StreamReader to read individual line of the text.
        }
    }

The file I am reading is show in the picture below. Please advise. Thanks.

enter image description here

mylim
  • 313
  • 4
  • 16
  • Side note: If this is file format you've invented consider using something more generic. For example JSON is very common choice for structured data with a lot of support to parse it in all languages. – Alexei Levenkov Dec 19 '17 at 04:01
  • Hi @Alexei Levenkov I dont really know much about JSON as I am quite a noob. Any advise? – mylim Dec 19 '17 at 04:49
  • @mylim You can try this code piece: `var file = await usbStorage.GetFileAsync("MyTestFile.txt"); var lines = await Windows.Storage.FileIO.ReadLinesAsync(file); foreach (var line in lines) { Debug.WriteLine("" + line.Split(';')[0]); }` – Rita Han Dec 20 '17 at 09:59

0 Answers0