コード例 #1
0
ファイル: Day04.cs プロジェクト: clvaughnsr/aoc2016
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        private RoomRec BuildRoomRec(string inVal)
        {
            const char   DASH  = '-';
            const char   OPEN  = '[';
            const string CLOSE = "]";

            // parse using '['
            var tempList = inVal.Split(OPEN);
            var front    = tempList[0];
            var checksum = tempList[1];

            // create checksum
            checksum = checksum.Replace(CLOSE, string.Empty);

            // create name and sector id
            var lastDash = front.LastIndexOf(DASH);
            var name     = front.Substring(0, lastDash);
            var sectorId = Convert.ToInt32(front.Substring(lastDash + 1));

            // build new rec
            var newRec = new RoomRec();

            newRec.name     = name;
            newRec.sectorId = sectorId;
            newRec.checksum = checksum;

            return(newRec);
        }