I need help
I need to store data's inside variable for later use.
i have a file which look like this
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
now i need to store these lines with all string ,did i need to use list or array.
thanks in advance
VulpesPosted Sep 30, 2013, 6:59 AM
krishnakumar kunaPosted Sep 30, 2013, 9:00 AM
VulpesPosted Sep 30, 2013, 8:23 AM
To access the number property of the i'th line, you'd then use lines[i].number.
krishnakumar kunaPosted Sep 30, 2013, 7:52 AM
Did i need to create class with how many variable i need to store.
could you please if it is correct
public void lineclass()
{
string name;
int number;
}
and use var lines =new list
please help i dont know about this thank you
krishnakumar kunaPosted Sep 30, 2013, 6:38 AM
this will help
A file like this
john,1432,somedata,somedata
kumar,564,somedata,somedata
jai,34241,somedata,somedata
now from the file i need these data for each person or each line to be read and stored in a variable .so, that later from the these variable i will write the data to a database.
now i a m using array where for every loop i need to run insert statement ,but if i use in a collection i could access any line at any time.
eg:
string data
string[] line;
while(data=sr.readline(file)!=null)
{ line=data.split(,)
label1.text=line[0];
}
i access those data inside while loop itself as when the loop loops second time the data in array list get overlaped with new data,as you know better than me.but what i want is i want to access all 5 lines even after the loop is finished.
like after loop is finished
label1.text=line[1][0];(i know this is wrong because this is not a multidimensional array)
for 3rd line
label3.text=linep[3][0]
thanks again.sorry for the trouble.
VulpesPosted Sep 30, 2013, 4:38 AM
If so, try this (off 'top of head', untested):
var lines = new List
using (var sr = new StreamReader("kk.txt"))
{
string line = null;
while((line = sr.ReadLine()) != null)
{
string[] items = line.Split(',');
if (items.Length == 5) lines.Add(line);
}
}
krishnakumar kunaPosted Sep 30, 2013, 4:28 AM
but i need to loop and store all data that is five string values in it and looping through all lines all string should be stored.
how?
thanks in advance
VulpesPosted Sep 30, 2013, 4:25 AM
using System.IO;
// ...
string[] lines = File.ReadAllLines("kk.txt");