Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Gedcom Reader
<pre class='prettyprint' language='C#'>using System.Collections.Generic; using System.IO; namespace GedcomReader { class Gedcom { private string GedcomText = ""; public struct INDI { public string ID; public string Name; public string Sex; public string BDay; public bool Dead; public string FamS; public string FamC; } public struct FAM { public string FamID; public string Type; public string IndiID; } public List<INDI> Individuals = new List<INDI>(); public List<FAM> Families = new List<FAM>(); public Gedcom(string fileName) { //reads in the file as a block of text using (StreamReader SR = new StreamReader(fileName)) { GedcomText = SR.ReadToEnd(); } ReadGedcom(); } private void ReadGedcom() { //Replaces "0 @" with an abratray char then splits on it to get the diffrent nodes of the gedcom file string[] Nodes = GedcomText.Replace("0 @", "\u0646").Split('\u0646'); foreach (string Node in Nodes) //searched though the nodes to see what type they are { string[] SubNode = Node.Replace("\r\n", "\r").Split('\r'); if (SubNode[0].Contains("INDI")) // im currently only intrested in the indi (individual) tag and the fam(family) tag all others get thrown out. { Individuals.Add(ExtractINDI(SubNode)); } else if (SubNode[0].Contains("FAM")) { Families.Add(ExtractFAM(SubNode)); } } } private FAM ExtractFAM(string[] Node) { string sFID = Node[0].Replace("@ FAM", ""); string sID = ""; string sType = ""; foreach (string Line in Node) { // If node is HUSB if (Line.Contains("1 HUSB ")) { sType = "PAR"; sID = Line.Replace("1 HUSB ", "").Replace("@", "").Trim(); } //If node for Wife else if (Line.Contains("1 WIFE ")) { sType = "PAR"; sID = Line.Replace("1 WIFE ", "").Replace("@", "").Trim(); } //if node for multi children else if (Line.Contains("1 CHIL ")) { sType = "CHIL"; sID = Line.Replace("1 CHIL ", "").Replace("@", ""); } } FAM Fam = new FAM(); Fam.FamID = sFID; Fam.Type = sType; Fam.IndiID = sID; return Fam; } private INDI ExtractINDI(string[] Node) { //string[] SubNode = Node.Replace("\r\n", "\r").Split('\r'); //If a individual is found INDI I = new INDI(); //Individual I = new Individual(); if (Node[0].Contains("INDI")) { //Create new Structure //Add the ID number and remove extra formating I.ID = Node[0].Replace("@", "").Replace(" INDI", "").Trim(); //Find the name remove extra formating for last name I.Name = Node[FindIndexinArray(Node, "NAME")].Replace("1 NAME", "").Replace("/", "").Trim(); //Find Sex and remove extra formating I.Sex = Node[FindIndexinArray(Node, "SEX")].Replace("1 SEX ", "").Trim(); //Deterine if there is a brithday -1 means no int BirthTest =FindIndexinArray(Node, "1 BIRT "); if (BirthTest != -1) { // add birthday to Struct I.BDay = Node[BirthTest + 1].Replace("2 DATE ", "").Trim(); } // deterimin if there is a death tag will return -1 if not found int DeathTest = FindIndexinArray(Node, "1 DEAT "); if (DeathTest != -1) { //convert Y or N to true or false ( defaults to False so no need to change unless Y is found. if (Node[DeathTest].Replace("1 DEAT ", "").Trim() == "Y") { //set death I.Dead = true; } } int FamsTest = FindIndexinArray(Node, "1 FAMS "); if (FamsTest != -1) { I.FamS = Node[FamsTest].Replace("1 FAMS ","").Replace("@", "").Trim(); } int FamcTest = FindIndexinArray(Node, "1 FAMC "); if (FamcTest != -1) { I.FamC = Node[FamcTest].Replace("1 FAMC ", "").Replace("@", "").Trim(); } } return I; } private int FindIndexinArray(string[] Arr, string search) { int Val = -1; for (int i = 0; i < Arr.Length; i++) { if (Arr[i].Contains(search)) { Val = i; } } return Val; } } }</pre> <a href="http://www.refactormycode.com/codes/873-gedcom-reader" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>