Thursday, August 20, 2009

Transforming text file data

I have now transformed the raw data from my VB Application - Active Math so that it looks like this:

7/28/2000 12:41:55 PM11 3+3 1 27
7/28/2000 12:41:55 PM11 2+2 1 27
7/28/2000 12:41:55 PM11 1+1 1 35
7/28/2000 12:41:55 PM11 4+4 1 32
7/28/2000 12:41:55 PM11 5+3 1 8

I'll refrain from posting the code, but the important links were first the Character Streams lesson, especially the example from the lower half of the page entitled Line-Oriented I/O. Also from the same thread was the lesson entitled Scanning. This has nothing to do with flat bed scanners, and in VB would probably be called parsing. From this lesson I followed the link to the scanner class in the API and reversed up to the parent package (java.util) and then back down to the StringTokenizer class.

Useful forum threads were this one, which gave me the idea of using the StringTokenizer, and this one, which discussed how to use it.

I then needed some to store the data, while reading it. The relevant main trail here is Collections, and within that Collection Interfaces, and within that I chose The List Interface. The particular implementation of this interface, which I selected, for no particular reason, was ArrayList. This had all the methods I needed to add elements one at a time, read them back, and clear them as and when needed.

Finally I returned to the Character Streams lesson to write the transformed data back to a new text file. In so doing I sidestepped data design and connection issues, so that I could concentrate on the mechanics of reading text file data and transforming it.

No comments: