Substring Text File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Walter Thizo
    New Member
    • Oct 2008
    • 13

    Substring Text File

    Hi Programmers

    Look at the text files below -

    ............... ............... ............... ............... ............... ............... ............... .......
    18-JUL-2008 11:10 JOKOTO UNIVERSITY Page : 1

    Dept : 6601 - BUSINESS INFORMATICS
    Subject : IDC30AE - INDUSTRY EXPOSURE IIIA

    Class Group : A
    Responsible Lecturer(s): 5000282 MR H MATOLO (Primary)
    Student
    Number and Name
    800128241 MOLOOI,DI
    804282322 KOPEN,BT
    ............... ............... ............... ............... ............... ............... .............

    My Question :


    This is the format of text file that i am working with , my task is to start by substring from Dept but i failed to do that , what i can do is to substring from begin of files, can u pls guysb give me idea?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Walter Thizo
    Hi Programmers

    Look at the text files below -

    ............... ............... ............... ............... ............... ............... ............... .......
    18-JUL-2008 11:10 JOKOTO UNIVERSITY Page : 1

    Dept : 6601 - BUSINESS INFORMATICS
    Subject : IDC30AE - INDUSTRY EXPOSURE IIIA

    Class Group : A
    Responsible Lecturer(s): 5000282 MR H MATOLO (Primary)
    Student
    Number and Name
    800128241 MOLOOI,DI
    804282322 KOPEN,BT
    ............... ............... ............... ............... ............... ............... .............

    My Question :


    This is the format of text file that i am working with , my task is to start by substring from Dept but i failed to do that , what i can do is to substring from begin of files, can u pls guysb give me idea?
    Simply read the first two lines and discard them. The third line you read will be the
    line you want to process.

    kind regards,

    Jos

    Comment

    • Walter Thizo
      New Member
      • Oct 2008
      • 13

      #3
      Originally posted by JosAH
      Simply read the first two lines and discard them. The third line you read will be the
      line you want to process.

      kind regards,

      Jos

      I appreciate your respond but look what i did (Code below)-


      //loop through the file
      for (int x=0 ; x < 21 ; x++)
      {


      //read the first line and delete
      Space = OneFileLine.Pos ("-");
      IDStud = OneFileLine.Sub String(1,Space-1 ) ;
      OneFileLine = OneFileLine.Del ete(1,Space );

      Comma = OneFileLine.Pos (":");
      StudSurname = OneFileLine.Sub String(1,Comma-1 ) ;
      OneFileLine = OneFileLine.Del ete(1,Comma );


      but my problem is that line is too long ,maybe can u give me shortest method of reading line and discard pls ?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        What language is that? Is it C#? This is a C and C++ forum; nevertheless, if you're
        talking C++ have a look at the istream.getline () function, if you're talking C have
        a look at the fgets() function.

        kind regards,

        Jos

        Comment

        • Walter Thizo
          New Member
          • Oct 2008
          • 13

          #5
          Originally posted by JosAH
          What language is that? Is it C#? This is a C and C++ forum; nevertheless, if you're
          talking C++ have a look at the istream.getline () function, if you're talking C have
          a look at the fgets() function.

          kind regards,

          Jos

          Jos , it is C++ and all i want is a logic of how can i use getline function to solve my problem because I did use getline fuction to read all records inside the text file .So pls can u give me the logic

          Kind Regards

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Walter Thizo
            Jos , it is C++ and all i want is a logic of how can i use getline function to solve my problem because I did use getline fuction to read all records inside the text file .So pls can u give me the logic

            Kind Regards
            I already gave you the best options in reply #4. Just read and discard the first
            two lines before you start your loop.

            kind regards,

            Jos

            Comment

            Working...