By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,354 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,354 IT Pros & Developers. It's quick & easy.

Complex file parsing

P: 5
I'm relatively new to VB programming (VB 2005), and have come across a problem parsing complex text files. Basically I have a file which has lines something like the following:

[WEIGHT_AND_BALANCE]
max_gross_weight = 150000 // (pounds)
empty_weight = 74170 // (pounds)

max_number_of_stations = 50

station_load.0 = "170.0, 41.0, -1.5, 0.0, Pilot" //Weight (lbs),
station_load.1 = "170.0, 41.0, 1.5, 0.0, Co-Pilot" //Weight (lbs),
station_load.2 = "510.0, 0.0, 0.0, 0.0, Crew" //Weight (lbs),
station_load.3 = "1360.0, 25.5, 0.0, 0.0, First Class" //Weight (lbs),

What I need to do is search the file to find the 'empty_weight' line for example and find the value after the = sign. Similarly, with the station_load sections, I would need the first number after the quotations, as integers and disregard the rest of the line.

I am not sure how to achieve this, I can do simple text parsing with a single delimiter, but don't really know where to start with much more complex files.

Thanks.
Apr 7 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
I'm not going to go into detail, because I work in VB6 and would possibly just confuse you. But I'd suggest all you need to do is read the text line by line. For each line, you check whether Left(Text, nn) = "your string". If so, then discard that part of the line. Look through the rest of the line, character by character until you hit something which is not a numeric digit (most likely using the Mid() function). Then just take everything before that point as your value.

If you know there will always be, for example, a space after the number, then you can save time by using something like Instr() function to find the space.
Apr 8 '07 #2

P: 5
Thanks. Sounds easy enough, I will try it out.
Apr 8 '07 #3

Expert 5K+
P: 8,434
Thanks. Sounds easy enough, I will try it out.
Let us know how it goes.
Apr 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.