日期:2014-05-17  浏览次数:21443 次

split分割后,怎么取到分割后的值
            operList[] = {"mst002_view","mst002_Save","mst001_Editor"........};
            for (int i = 0; i < operList.Count; i++)
            {
                var competenceId = operList[i];
                competenceId.Split('_');
            }
 
分割后就是成了   mst002 和 view  
                 mst002 和 Save
                 mst001 和 Editor
                 .......
                                   我怎样才能拿到前半个值和后半个值呢
------最佳解决方案--------------------
 var operList = new string[] { "mst002_view", "mst002_Save", "mst001_Editor" };
             var ary1 = operList.Select(t => t.Split('_')[0]).ToArray();
             var ary2 = operList.Select(t => t.Split('_').Length > 1 ? t.Split('_')[1] : "").ToArray();
            
------其他解决方案--------------------
operList[] = {"mst002_view","mst002_Save","mst001_Editor"........};
             for (int i = 0; i < operList.Count; i++)
             {
                 var competenceId = operList[i];
                 string [] cp = competenceId.Split('_');
     
                     string a1 = cp[0]; // _  左边的数据  mst002   mst002
                     string a2 = cp[1]; // _  右边的数据  view     Save

             }
  
 分割后就是成了   mst002 和 view  
                  mst002 和 Save
                  mst001 和 Editor
------其他解决方案--------------------
引用:
var