当前位置:编程学习 > C#/ASP.NET >>

把数组按固定长度分割的问题

135,136,138,139,150,131,133,132,130,134
这是一串字符.中间以,隔开.现在需要每3条做为一个值存入别的地方
分开后的效果是
135,136,138
139,150,131
133,132,130
134
请问怎么实现 --------------------编程问答-------------------- split('.') --------------------编程问答-------------------- string s = "135,136,138,139,150,131,133,132,130,134 ";
string[] temp = s.Split(',');
string showResult = null;
for (int i=0;i<temp.Length;i++)
{
if ((i+1)%3 == 0)
{
showResult += temp[i]+"\n";
}
else
{
showResult += temp[i]+",";
if ((i+1) == temp.Length)
{
showResult = showResult.Remove(showResult.Length -1 ,1);
}
}
}
MessageBox.Show(showResult); --------------------编程问答--------------------
Regex reg=new Regex(@"(\d+,){0,2}\d+");
string str="135,136,138,139,150,131,133,132,130,134 ";
string result=string.Empty;
foreach(Match m in reg.Matchs(str))
{
 result+=m.Value+"\r\n";
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,