Reading Text File in C#

Posted by Kpoudyal2012 under ASP.NET on 7/20/2012 | Points: 10 | Views : 1913 | Status : [Member] | Replies : 5
.Net Gurus,
I have a three text file with similar format of text inside the folder c:\Job \ (test1.txt, 1.test2.txt, test3.txt)
see below the format for the text file
---------------------------------------------------
test1.txt

Yogesh Patel has 23 credits to be earned to .....(line1)

his id#90000 - (line3)
his GPA: 87 (line5)

My question is how will i retrieve following information
Yogesh Patel (Which start with indexOf 0 position in the text file
ID#90000
GPA: 87

once i get this informatio from test1.txt again i need to move to test2.txt file inside the same folder and retrieve same kinds of information
Rekha Gupta
ID#23233
GPA:90 then finally look for test3.txt
at the end all of the data i looped thru these three different file i need to store in SQL server.
How can i accomplish this task ? Any suggestion pls ?




Responses

Posted by: CGN007 on: 7/20/2012 [Member] Silver | Points: 25

Up
0
Down
Let me know ,What you have done so far...?

Kpoudyal2012, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/20/2012 [Member] Starter | Points: 25

Up
0
Down
Please post your code that you have written till now...

____________
www.flickr.com/photos/psdesigner/

Kpoudyal2012, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 7/21/2012 [Member] Silver | Points: 25

Up
0
Down
attach ur "text1.txt" file...

Regards,
Singaravel M

Kpoudyal2012, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 7/22/2012 [Member] Silver | Points: 25

Up
0
Down
u can use regex...

Regards,
Singaravel M

Kpoudyal2012, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oswaldlily on: 7/23/2012 [Member] Starter | Points: 25

Up
0
Down
struct details
{
public string name;
public string id;
public string GPA;

}
main()
{

StreamReader logreader = File.OpenText("D:\\set\\ConsoleApplication2\\ConsoleApplication2\\bin\\Debug\\test.txt");
string data = "";
data = logreader.ReadToEnd();
int start = data.IndexOf("Yogesh");
int end = data.IndexOf("87");
string sresult = data.Substring(start, end - start - 1);
char[] delimiters = new char[] { '\r', '\n' };
string[] splitt = sresult.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); /*STORE LINE BY LINE */
List<details> list1 = new List<details> STORE STRUCTURE INTO LIST */
char[] separator = { ' ' };

for (int i = 1; i <= (split.Length - 1); i++)
{
details e = new details();

e.name = split[i].Substring(1, 12).TrimStart(separator).TrimEnd(separator);
e.id = split[i].Substring(1,5).TrimStart(separator).TrimEnd(separator);
e.GPA = split[i].Substring(1,2).TrimStart(separator).TrimEnd(separator);

list1.Add(e);

}
}

Kpoudyal2012, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response