您的位置:首页 > 编程语言 > C#

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

2012-05-13 23:21 1021 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐