Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Find Year from text in C#

Find Year from text in C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    montu3377
    wrote on last edited by
    #1

    Hi, I have one flat file which contains data in particular format.The file contains data in particular format which generates pages. Each page contains Year in MM/DD/YYYY format which always starts with specific position means specific x,y coordinate, so out of this it will generate N no of pages. There are multiple dates available in one page like YearStarting , YearEnding etc and out of this i want to find out only particular date like YearStarting. I don't want to find out values for YearEnding. My requirement is that i have to find out each and every YearStarting value contains in the flat file from first line to end of the reports. YearStarting data is having specific position in each pages. Can some one tell me how to find out each value of Year from the Flat file(or text file) using C#?? Thanks a lot.

    R M L 3 Replies Last reply
    0
    • M montu3377

      Hi, I have one flat file which contains data in particular format.The file contains data in particular format which generates pages. Each page contains Year in MM/DD/YYYY format which always starts with specific position means specific x,y coordinate, so out of this it will generate N no of pages. There are multiple dates available in one page like YearStarting , YearEnding etc and out of this i want to find out only particular date like YearStarting. I don't want to find out values for YearEnding. My requirement is that i have to find out each and every YearStarting value contains in the flat file from first line to end of the reports. YearStarting data is having specific position in each pages. Can some one tell me how to find out each value of Year from the Flat file(or text file) using C#?? Thanks a lot.

      R Offline
      R Offline
      RCoate
      wrote on last edited by
      #2

      You could try regular expressions.

      M 1 Reply Last reply
      0
      • R RCoate

        You could try regular expressions.

        M Offline
        M Offline
        montu3377
        wrote on last edited by
        #3

        I have multiple columns which contains Year format, so basically year format is NOT unique thru out the file, so if i use regular expression then it will fetch values from multiple column and i want all the values from specific single column.

        P 1 Reply Last reply
        0
        • M montu3377

          Hi, I have one flat file which contains data in particular format.The file contains data in particular format which generates pages. Each page contains Year in MM/DD/YYYY format which always starts with specific position means specific x,y coordinate, so out of this it will generate N no of pages. There are multiple dates available in one page like YearStarting , YearEnding etc and out of this i want to find out only particular date like YearStarting. I don't want to find out values for YearEnding. My requirement is that i have to find out each and every YearStarting value contains in the flat file from first line to end of the reports. YearStarting data is having specific position in each pages. Can some one tell me how to find out each value of Year from the Flat file(or text file) using C#?? Thanks a lot.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Pseudo code open the file (System.IO) read line (System.Text) test that it contains the YearStarting pattern in the text (System.Text or regex) extract the first date after pattern (System.Text or regex) store the details (System.Data) repeat test if it is possible to have more than 1 date per line repeat line 2 until end of file close file Fairly simple really

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • M montu3377

            I have multiple columns which contains Year format, so basically year format is NOT unique thru out the file, so if i use regular expression then it will fetch values from multiple column and i want all the values from specific single column.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Not if you write your expression properly. We'd need to see a sample of the file.

            1 Reply Last reply
            0
            • M montu3377

              Hi, I have one flat file which contains data in particular format.The file contains data in particular format which generates pages. Each page contains Year in MM/DD/YYYY format which always starts with specific position means specific x,y coordinate, so out of this it will generate N no of pages. There are multiple dates available in one page like YearStarting , YearEnding etc and out of this i want to find out only particular date like YearStarting. I don't want to find out values for YearEnding. My requirement is that i have to find out each and every YearStarting value contains in the flat file from first line to end of the reports. YearStarting data is having specific position in each pages. Can some one tell me how to find out each value of Year from the Flat file(or text file) using C#?? Thanks a lot.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Use a StreamReader to read the file into a List or some other “collection”. Iterate over the list looking for page start / end (e.g. form feeds or whatever). Since you know the x,y of the date in question, count “y” lines from the top / bottom of a “page”. Once you have the line in question, use “string” functions to get date at “x”; e.g. // Assumes x relative to 0 and date in mm/dd/yyyy format String strDate = line.SubString( x, 10 ); Then just convert the “string date” to a suitable format for further processing using Parse or whatever.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups