C#不使用Split()方法,遍历数组,使用“|”分割元素并输出

来源:互联网 发布:汇丰杯sas数据分析 编辑:程序博客网 时间:2024/05/21 06:20
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);


原创粉丝点击