Click here to Skip to main content
11,920,641 members (55,802 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0 string
Hi! I'm quit new to C# and I resentle stucked with some code and I would be very pleased to get some help.

I want to be able to take out a line from a .txt file with just knowing what the text is on the line above. For exemple:


And for exemple "Name:" will not stand on the same line all the time, it will variat from time to time.

I hope you understand my bad English.

best regards
Posted 28-Feb-13 2:31am
Edited 28-Feb-13 2:32am
Uday P.Singh 28-Feb-13 7:34am
why not put all your data in xml and retrieve from that
samadhan_kshirsagar 28-Feb-13 7:41am
its very easy......first of all check the file is present or not...then open the file.....and read the character from the file
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Well I think you should take Uday's suggestion into consideration but if you must read it from text file:
List<string> lines = new List<string>();
    // Read the file and display it line by line.
    System.IO.StreamReader file = new System.IO.StreamReader("c:\\yourtextfilepathhere.txt");
    while((line = file.ReadLine()) != null)

Do your manipulation when you have your list filled.

Good luck,
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Thank you for your quik answears.

The file looked like this:
<TD width="20%" class="WG3">Name&nbsp;</TD>
        <TD width="20%" class="WG3">Olof&nbsp;</TD>

I wrote the code like this and its works perfect.
<pre lang="cs">public string getMeetInfo(string fileContent , string searchMeetInfo)

    string searchString1 = ">" + searchMeetInfo + "&nbsp;</TD>";
    int IntRubrikStart = fileContent.IndexOf(searchString1);
    string searchString2 = ">";
    int intWantedNameStart = fileContent.IndexOf(searchString2, IntRubrikStart + searchString1.Length) + 1;
    string searchString3 = "&nbsp";
    int intWantedNameEnd = fileContent.IndexOf(searchString3, intWantedNameStart);
    string strOut = fileContent.Substring(intWantedNameStart, intWantedNameEnd - intWantedNameStart);
    return strOut;

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

this is not question this kind of assignment please send me file i will write code and send to you.
Orcun Iyigun 28-Feb-13 7:49am
you are not helping him this way. it is bad for him....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100