Fork me on GitHub

C#不使用Split()方法,遍历数组,使用“|”分割元素并输出 分类: C# 2012-05-13 23:21 1416人阅读 评论(0) 收藏

static void Main(string[] args)
        {
            string[] strBtu = { "cc", "vvv", "bbbb", "dd", "ggg", "mmmm" };
            string[] strBtu2 = new string[strBtu.Length + strBtu.Length - 1];

            int nIndex=0;           
            for (int i = 0; i < strBtu.Length; i++)
            {
                strBtu2[nIndex] = strBtu[i];
                nIndex++;
                if (nIndex < 11)
                {
                    strBtu2[nIndex] = "|";
                    nIndex++;
                }
                else
                {
                    break;
                }
            }

            for (int i = 0; i < strBtu2.Length; i++)
            {
                Console.Write(strBtu2[i]);
            }
            Console.ReadKey();
        }


使用windows控制台程序,输出数组的元素,并且使用“|”分割。


 //第二种方法

            string s = "";
            for (int i = 0; i < strBtu.Length - 1; i++)
            {
                s = s + strBtu[i] + "|";
            }
            s = s + strBtu[strBtu.Length - 1];

            Console.Write(s);


版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2012-05-13 23:21  zhiqiang21  阅读(276)  评论(0编辑  收藏  举报