Question Locked

Extracting Text from a Text File

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi guys,

I am stuck for developing a logic, Please help me. Below is the Scenerio....
-------------sample text file-------------
I have a text file like this...
01hjbdksfsfsndfsjfhbwdefw...
02kjfkwdfkkdfkfkwk
03ksjfkjfrbgfejkrgfehj
04sdbkjdfkjrfr
03kjnfkejrkejg
04kjdfkjekjgkejg
05kjbfeebgrjkebrgekg
02bdfhjrfehjrgfjrgebrkg
03kjgkjkjtg
04kljgtkb mgn bk
05ltrermtnljkb
----------------------------------
if u look at it, u will find that it is divided into batches(from row 02 to 05 constitute single batch)and i have mentioned two batches.
The real task is that i have to process batch after batch looking if there is any error in any batch, discard that batch and move toward another batch.

Till now i am trying to develop logic using stream reader but with that its complicated to handle errors.

can u suggest something?

6 replies

by vishalluthra

I am already using Stream Reader, but the problem is i am wanna extract batch after batch. Look in to my post for more...

by tony hopkinson

I can't see any indication that rows two to five are a batch!

A Bit Of lateral thinking

Create a class Batch to hold the lines of the batch
Another batches to hold a list of Batch
Put a loadfromStream on Batches and Batch, once you've got the data into the structure, then just iterate through batches and then Batch.

by vishalluthra

That?s why its bit tricky, as u r saying that it doesn't have any indication, honestly it has; first two integers of each line give you indication
02-Start of batch
05-End of batch
We need to read the data between these two lines which is variable i.e. lines 03 and 04
-But, number of lines starting with 03 will be equal to no. of lines starting with 04 in every batch.
-& 02 and 05 lines can never be more than one per batch.

So it?s become simple to read data in batch.

I have solved problem by myself.
But, I really appreciate Ur post.
Thanks a lot.

by tony hopkinson

2 is start of batch 5 is end.

Obvious really :D

Should have known, silly me.

No problem, if bouncing a few ideas off my head got you out of the hole you were in, purpose served.

This discussion is closed to new replies.