// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; using System.IO; namespace E { public class MyObject { private int guid; private int type; private int entry; public MyObject() : this(0, 0, 0) { } public MyObject(int guid, int type, int entry) { this.guid = guid; this.type = type; this.entry = entry; } public int Guid { get { return guid; } set { guid = value; } } public int Type { get { return type; } set { type = value; } } public int Entry { get { return entry; } set { entry = value; } } public override String ToString() { return ("[" + guid + "," + type + "," + entry + "]"); } } public class MainClass { private const String START = "#OBJECT START"; private const String END = "#OBJECT END"; private const String GUID = "OBJECT_FIELD_GUID"; private const String TYPE = "OBJECT_FIELD_TYPE"; private const String ENTRY = "OBJECT_FIELD_ENTRY"; public static void Main(string[] args) { ArrayList lst = new ArrayList(); StreamReader sr = new StreamReader(@"C:\test.txt"); String line; bool active = false; MyObject mo = null; while((line = sr.ReadLine()) != null) { if(line.StartsWith(START)) { active = true; mo = new MyObject(); } else if(line.StartsWith(END)) { lst.Add(mo); active = false; } else { if(active) { string[] parts = line.Split(":".ToCharArray()); string key = parts[0].Trim(); string val = parts[1].Trim(); if(key.StartsWith(GUID)) { mo.Guid = int.Parse(val); } else if(key.StartsWith(TYPE)) { mo.Type = int.Parse(val); } else if(key.StartsWith(ENTRY)) { mo.Entry = int.Parse(val); } else { throw new Exception("Unrecognized line " + line); } } } } sr.Close(); for(int i = 0; i < lst.Count; i++) { Console.WriteLine(lst[i]); } } } }