Reading Text Based File with an Odd Delimited Format

Trying to get pointers on where to look for some help

Page 1 of 1

3 Replies - 887 Views - Last Post: 16 September 2009 - 09:32 AM Rate Topic: -----

#1 garyt@shaw.ca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-September 09

Reading Text Based File with an Odd Delimited Format

Posted 15 September 2009 - 11:28 AM

I am looking for some general ideas on where to look for some help/pointers on I have a text file i wish to parse out so that i can manipulate individual elements. The thing is that it seems to me it is a non standard format to parse. Now it just may be my rustiness and not anything actually wrong with the data format but here is a sample of the file i wont post the entire file since it is 16 megs long. What i'm looking for is just some direction on what language elements i might use to parse this out. I'm a VB.NET programmer by trade but thought this might be a way for me to get my head in to the C# space.

date="1940.1.1.0"
player="JAP"
ai={
0 0 0 0 0 7 0 }
automate_trade=no
automate_sliders=0
rebel=66
convoy=6305
theatre=53414
unit=6226
flags={
}
gameplaysettings={
	setgameplayoptions={
1	 }
}
id={
	id=25345
	type=4713
}
1={
	owner="NOR"
	controller="NOR"
	core="NOR"
	infra={
 4.000 4.000	 }
	points=0
	weather={
		temperature=-13.016
		precipitation=0.004
		frozen=0.500
		cloud_coverage=0.002
	}
}
2={
	owner="NOR"
	controller="NOR"
	core="NOR"
	infra={
 4.000 4.000	 }
	points=0
	weather={
		temperature=-13.091
		precipitation=0.004
		frozen=0.500
		cloud_coverage=0.002
	}
}
3={
	owner="NOR"
	controller="NOR"
	core="NOR"
	infra={
 4.000 4.000	 }
	points=0
	weather={
		pressure=1017.000
		temperature=-13.150
		precipitation=0.004
		frozen=0.501
		cloud_coverage=0.002
	}
}
4={
	owner="NOR"
	controller="NOR"
	core="NOR"
	infra={
 4.000 4.000	 }
	points=0
	weather={
		pressure=1017.000
		temperature=-6.104
		precipitation=0.004
		frozen=0.250
		cloud_coverage=0.002
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Reading Text Based File with an Odd Delimited Format

#2 sam.adams61  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 283
  • Joined: 14-July 08

Re: Reading Text Based File with an Odd Delimited Format

Posted 15 September 2009 - 11:35 AM

Why not use double.Parse and/or double.TryParse. Such are used to convert strings to integers and such. Maybe, this is not what you're looking for...it's just my few bobs worth...or few cents for you good USA & Canadian folk!
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Reading Text Based File with an Odd Delimited Format

Posted 15 September 2009 - 12:00 PM

From what I can tell, every element has an equal sign. So, I would probably create a dictionary of key/value pairs where keys are the strings to the left of the equal sign, and then read each line in the file. On each line read, parse the line by first trimming out leading/trailing white space. Then split on equal sign. Identify that the value on the left matches a key entry in your dictionary, and then if so, update the value to the value on the right of the equal sign.

Does that make sense?
Was This Post Helpful? 0
  • +
  • -

#4 garyt@shaw.ca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-September 09

Re: Reading Text Based File with an Odd Delimited Format

Posted 16 September 2009 - 09:32 AM

View PostMentalFloss, on 15 Sep, 2009 - 11:00 AM, said:

From what I can tell, every element has an equal sign. So, I would probably create a dictionary of key/value pairs where keys are the strings to the left of the equal sign, and then read each line in the file. On each line read, parse the line by first trimming out leading/trailing white space. Then split on equal sign. Identify that the value on the left matches a key entry in your dictionary, and then if so, update the value to the value on the right of the equal sign.

Does that make sense?

yes it does thank you. To both you and sam that gives me a good starting point.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1