Question

I have stored a text file into isolated storage, my file is saved in a way of "asdasdasd,asdasdasd", how can I use delimiters to spilt them instead of retrieving the whole string like this:

        //Get the Store we created earlier
        IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
        //use a StreamReader to open and read the file           
        StreamReader readFile = null;
        try
        {
            readFile = new StreamReader(new IsolatedStorageFileStream("SaveFolder\\SavedFile.txt", FileMode.Open, store));
            string fileText = readFile.ReadToEnd();

            //The control txtRead will display the text entered in the file
            textBlock2.Text = fileText;
            readFile.Close();
        }

        catch
        {
            //For now, a simple catch to make sure they created it first
            //we will modify this later
            textBlock2.Text = "Need to create directory and the file first.";
        }
Was it helpful?

Solution

You can use string.Split method to split string delimited by the specified characters:

string fileText = readFile.ReadToEnd();
string[] substrings = fileText.Split(',');

Then you can access each substring by an array index, for example:

textBlock1.Text = substrings[0];
textBlock2.Text = substrings[1];

Note: It would be better to check if substrings array have at least those two elements.

OTHER TIPS

to split them, split the fileText like so:

string fileText = readFile.ReadToEnd();

string[] splitText = fileText.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);

you now have an array in the splitText. It now contains individual entries

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top