首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

按指定长度分割字符串 【喔】

2013-08-04 
按指定长度分割字符串 【在线等喔】大致是这样! 随机方法RonDom_str得到一组6位数的字符串,我加了num判断随

按指定长度分割字符串 【在线等喔】
大致是这样!
 随机方法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);
            }


[解决办法]
引用:
大致是这样!
 随机方法RonDom_str得到一组6位数的字符串,我加了num判断随机产生多少组随机数
  

        public string RonDom_str(int num)
        {
            Random rd = new Random();
            string str = "0123456789";
            string result = "";          
            for (int j = 0; j < num; j++)
            {
                for (int i = 0; i < 6; i++)
                {
                    result += str[rd.Next(str.Length)];
                   
                }               
            }            
            return result;
        }



 返回的result里我想再进行分割,不知道如何用string[] stra = str.Split();
分割得到以6位数分割的数组!!
 RonDom_str(2);
 string result=123456123456;    
 str.split(?????????);
 string stra[]={123456,123456}; 

大神速解!!按指定长度分割字符串 【喔】
 
  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;
        }

热点排行