按指定长度分割字符串 【在线等喔】
大致是这样!
随机方法RonDom_str得到一组6位数的字符串,我加了num判断随机产生多少组随机数
string str = @"123456123456";
string strmatch = @"(?is)[\d]{6}";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str);
foreach (System.Text.RegularExpressions.Match mm in mc)
{
MessageBox.Show(mm.Value);
}
protected void Page_Load(object sender, EventArgs e)
{
List<string> newlist= RonDom_str(2);
string[] t = newlist.ToArray();
}
public List<string> RonDom_str(int num)
{
List<string> neli = new List<string>();
Random rd = new Random();
string str = "0123456789";
for (int j = 0; j < num; j++)
{
string result = "";
for (int i = 0; i < 6; i++)
{
result += str[rd.Next(str.Length)];
}
neli.Add(result);
}
return neli;
}