字符串数组将每一个字符串分割成两个字符为一组

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ConPra
{
    class Program
    {
        public static void Main(string[] Args)
        {
            List<string> names = new List<string>();
            names.Add("ganquanfu1");
            names.Add("ligang2");
            names.Add("daizhangmin3");
            names.Add("zhujiejun4");
            foreach (var item in names)
            {
                int index = 0;
                int len = item.Length;
                while (index<=len-1)
                {
                    string tem=string.Empty;               
                 
                     if(index==len-1)
                    {
                        tem = item.Substring(index, 1);
                    }
                     else
                     {
                         tem = item.Substring(index, 2);
                     }
 
                    Console.Write(tem + " ");
                    index += 2;
                }
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}

posted @ 2013-04-25 20:39  Predator  阅读(1797)  评论(0编辑  收藏  举报