日期:2014-05-18 浏览次数:20649 次
string test_str = "000111100 "; List<string> temp_list = new List<string>(); List<string> result_list = test_str.ToList().Select((a, i) => { string temp_save = null; if (a == '0') { temp_save = "A" + (temp_list.Where(b => b.Contains("A")).Count()); temp_list.Add("A"); return temp_save; } else { temp_save = "B" + (temp_list.Where(b => b.Contains("B")).Count()); temp_list.Add("B"); return temp_save; } }).ToList(); /* * [0] "A0" string [1] "A1" string [2] "A2" string [3] "B0" string [4] "B1" string [5] "B2" string [6] "B3" string [7] "A3" string [8] "A4" string [9] "B4" string */