Friday, August 20, 2010

Pls help me out.. i have doubt in C#?

hi every body.. i want to know how to fetch a particular data from a text file.. not the entire file and place those datas into some control like datagrid or dataview using C#.Net... pls help me out how to do this..Pls help me out.. i have doubt in C#?
u fill use System.IO namespace for that





i know vb.net,in vb.net i can do it.but i can read the first line





fileiovar.readline()





but i dont know how its in c#





if u want a part in a text file u can look for searching-techniques.but im sure its all about System.IOPls help me out.. i have doubt in C#?
Read data connections using text drive r..this may help you out..


Have a nice day
StreamReader class can be used for retrieving data from the text file. The programming logic varies depended on the type of data file.





IF You have no idea the actual data, but the data type is xml or html. You need to know its open tag and close tag, and the data is being placed between them. Following is the example in C#.NET in handling xml file.


--------------------------------------鈥?br>

int iopentag;


' this is for recording the position of opening tag


int iclosetagpos;


' this is for recording the position of closing tag


string stropentag = ';%26lt;name%26gt;';;


string strclosetag = ';%26lt;/name%26gt;';;


string strxmlcontent; (the file is in binary format, you need to encode it to text, otherwise it will not work. I can't remember how to do it at moment.)


string stractualvalue;


int inumberofcharacterstostrip;


'This value is to determine how many characters to strip





iopentag = strxmlcontent.indexof(stropentag);


if iopentag %26gt; -1 {


if iclosetag %26gt; -1 {


inumberofcharacterstostrip = iclosetag - iopentag - stropentag.size;


stractualvalue = strxmlcontent.substring(iopentag + stropentag.length, inumberofcharacterstostrip);


}else{


Message.show(';This file is invalid!!!';);


}


}


///////


This is an example of retrieving one data from the text file. In the realworld situation, the pesuedo-code is as follow:


--------------------------------------鈥?br>

Get the current postion of opentag


Do while current position is greater than zero


If the end tag position is greater than zero then


get the actual number of characters to strip by opentagpos less closetagpos less length of starttagstring


get the start position to strip by start tag pos. plus length of start tag string (might be less 1, please try!)


Using substring property (start position to strip, actual number of characters to strip)


Change the open tag pos by (strxmlcontent.indexof(stropentag, iendtagpos))


Else


set opentag pos is -1


End if


End While





if closetag is -1 then


Prompt the message ';the file is invalid';.


end if





I have provided the logic tailerd to your case, hope my message will solve your programming problems. Are you uni student?

No comments:

Post a Comment