110,537
社区成员
发帖
与我相关
我的任务
分享
string str7 = Judgement_frf(dataGridView1.Rows[0].Cells[0].Value.ToString());
feirenfang.SetCellValue(str7);
上述为输出的字符串,输出效果如下现在想把这个字符串按照每6组分割一次然后分别存入新的字符串里面,有什么好的方法吗?string txt = "123-123;45-123;123-123;45-123;123-123;45-123;1234-123;455-123;123-123;45-123;123-123;45-123;45-123;";
foreach (var s in Regex.Split(txt, @"(?<=^(?:(?:\d+\-\d+;){6})+)"))
{
Console.WriteLine(s);
}
Regex.Matches(txt,@"(\d+\-\d+;){6}")
{
string s = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15";
List<string> result = new List<string>();
int i = 0;
string temp=string.Empty;
foreach(var v in s.Split(','))
{
if (++i<=6)
{
temp += v;
}
else
{
i = 0;
result.Add(temp);
temp = string.Empty;
}
}
if (temp!=string.Empty)
{
result.Add(temp);
}