日期:2014-05-18 浏览次数:21318 次
int counter=0; for(int i=0;i<array.Length;i++){ string lin=""; for(int j=0;j<array[i].Length;j++){ lin+=array[i][j]+" "; } lin=lin.Trim(); writeline2file(lin); counter++ if(counter%=5) writeline2file("A A A A A.."); }
------解决方案--------------------
StringBuilder value = new StringBuilder(); int length = 1000000; int rowlength = 5; int collength = 1 + rowlength; int ilength = (int)Math.Ceiling((double)(length / rowlength)); int mod = length % collength; if (mod == 0) { mod = collength; } int mini = 0; for (int i = 1; i <= ilength; i++) { int jlength; if (i < ilength) { jlength = collength; } else { jlength = mod; } for (int j = 0; j < jlength-1; j++) { value.AppendFormat("{0} ",i+ mini + j * rowlength); } value.AppendFormat("{0}\r\n", i + mini + (jlength - 1) * rowlength); if (i % rowlength == 0) { value.Append("A A A A A A\r\n"); mini += rowlength * rowlength; } } using (StreamWriter sw = new StreamWriter("./1.txt", false, System.Text.Encoding.UTF8, 8196)) { sw.Write(value.ToString()); }; MessageBox.Show("好了");