Write text from text file to list c# windows phone -


i beginer , don't know how write text file list strings. mean have file :

a b c d e f g h ... 

and want write list dont know how, maybe simple tried , doesnt work. have

list<list<string>> listakolumn = new list<list<string>>(); var str = application.getresourcestream(new uri("wzor.txt", urikind.relative)); streamreader sreader = new streamreader(str.stream);  int x = 0; while (!sreader.endofstream) { foreach (string k in sreader.readtoend().split(new char[] { ' ' }))             {                 int j = 0;                 foreach (string l in k.split(new char[] {' '}))                 {                     if (listakolumn.count < k.split(new char[] { ' '}).length)                     {                         listakolumn.add(new list<string>());                     }                     //double temp2;                     listakolumn[j].add(l);                     j++;                 }             } } 

but wrong. know how should in mind dontn know language , can't write it.

in short need text wite in multidimensional array array[0][0] = array[0][1]=b array[1][0] =c array[1][1] = d , on

here method pass in text file displayed in question , return multidimensional array.

public string[][] multiarrayfromtextfile(string filepath) {     return file.readlines(filepath).select(s => s.split(' ')).toarray(); } 

file.readlines(filepath) returns collection of lines in text file

.select extension method takes function.

s=>s.split(' ') function passed .select, splits string s spaces , returns array of strings.

.toarray() takes collection of string arrays created .select , makes array out of that, array of arrays.

you can access items in results this...

console.writeline(results[1][1]); // returns 'd' ... 2nd item of 2nd array 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -