日期:2014-05-18 浏览次数:21195 次
var lines = File.ReadAllLines(@"E:\我的项目文档\c.txt"); var sw = new StreamWriter(@"E:\我的项目文档\De.txt", false); var blen = 64; foreach (var item in lines) { string[] blks; var count = item.Length / blen; var rem = item.Length % blen; if (rem > 0) { blks = new string[count + 1]; blks[count] = item.Substring(blen * count, rem); } else { blks = new string[count]; } for (int i = 0; i < count; i++) { blks[i] = item.Substring(blen * i, blen); } sw.WriteLine("I[0] I[1] I[2] I[3] I[4] I[5] I[6] I[7] I[8] I[9] I[10] I[11]"); sw.WriteLine("X[0] X[1] X[2] X[3] X[4] X[5] X[6] X[7] X[8] X[9] X[10] X[11] X[12] X[13] X[14] X[15] X[16] X[17] X[18] X[19] X[20] X[21] X[22] X[23] X[24] X[25] X[26] X[27] X[28] X[29]"); sw.WriteLine("X[30] X[31] X[32] X[33] X[34] X[35] X[36] X[37] X[38] X[39] X[40] X[41] X[42] X[43] X[44]"); sw.WriteLine("X[45] X[46] X[47] X[48] X[49] X[50] X[51] X[52] X[53] X[54] X[55] X[56] X[57] X[58] X[59]"); sw.WriteLine("X[60] X[61] X[62] X[63] O[0] O[1] O[2] O[3] O[4] O[5] O[6] O[7] O[8] O[9] O[10] O[11]"); for (int i = 0; i < blks.Length; i++) { var str = blks[i]; var idxs = new List<int>(blen); var index = -1; while ((index = str.IndexOf('1', index + 1)) >= 0) { idxs.Add(index); } if (idxs.Count > 0) { var istr = i.ToString(); var sidxstr = idxs[0].ToString(); sw.WriteLine(string.Concat("M", istr, "[", sidxstr, "] O[", istr, "] X[", sidxstr, "] P", istr, "[", sidxstr, "]")); var lidx = idxs.Count - 1; for (int j = 1; j < lidx; j++) { var idxstr = idxs[j].ToString(); sw.WriteLine(string.Concat("M", istr, "[", idxstr, "] P", istr, "[", sidxstr, "] X[", idxstr, "] P", istr, "[", idxstr, "]")); sidxstr = idxstr; } if (idxs.Count > 1) { var eidxstr = idxs[lidx].ToString(); sw.WriteLine(string.Concat("M", istr, "[", eidxstr, "] P", istr, "[", sidxstr, "] X[", eidxstr, "] I[", istr, "]")); } sw.Flush(); } } }