Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Firstly I just want to thank those who have assisted me in my 2 recent questions. I have got them over and it's okay now. However, I'm working on a project to read several text files, validate them and process them to align it for processing by another system so I'll post for assistance regularly. So thank you to the code gurus who are assisting such intermediate programmers like me.

My next issue is, I have a text file. It has header strings which are rightpadded. What I want is to read the text file and pick up the date on the header. The header details are as follows.

H100 FileName Date Officer Test
jhashdjha ajshdja ahdjahdjahjdh hadjhdjahdjs aj hdja

H100 -is Padded Right 9, FileName - is padded Right 12, Date - is padded right 10, Officer - is padded right 12 and tes - is padded right 4.

After the header there are obviously other texts. Please assist to grab the Date from the header. I have searched the web adn couldn't grab something in line to this quickly so I'm asking.

Thanking in advance.
Posted
Updated 22-May-13 15:12pm
v2
Comments
Prasaad SJ 22-May-13 21:51pm    
Hi.. May I know what is this 9,12,10 numbers that you have specified.
ekipongi 22-May-13 23:45pm    
These are the padding values for the headers. E.g H100 has a padding of 9.

1 solution

So you are parsing a line of fixed width fields... Read the line in, take the first nine chars and store in H100, take the next 12 chars and store in FileName, continue until you have consumed all chars.

Then, use the variables that you have stored the data in for whatever tasks you need them for.

MSDN - How to read from a text file [^]

Other functions that will help you: left, right, mid, instr
 
Share this answer
 
v2
Comments
ekipongi 22-May-13 23:47pm    
Thanks _Damian S_. Could you please post some codes for that. I'v worked on it and I'm really stuck and need assistance urgently. Thanks
_Damian S_ 23-May-13 0:25am    
I've updated my answer above.
Abhinav S 23-May-13 0:27am    
5!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900