日期:2014-05-18 浏览次数:21139 次
string str = "xx,xxx,x,xxx,xxxxxx,xxxxx,xxxxxx,xxxxx,xxxxxxxxx,";
string[] arr = str.Split(",", 6);
/*
返回
arr[0] xx
arr[1] xxx
arr[2] x
arr[3] xxx
arr[4] xxxxxx
arr[5] xxxxx,xxxxxx,xxxxx,xxxxxxxxx,
*/
------解决方案--------------------
 
string i = "xx,xxx,x,xxx,xxxxxx,xxxxx,xxxxxx,xxxxx,xxxxxxxxx";
        string[] str = i.Split(',');
        string newstr = "";
        if (str.Length >= 5)
        {
            for (int j = 0; j < 5; j++)
            {
                newstr = newstr + str[j].ToString()+",";
            }
        }
        Response.Write(newstr);
------解决方案--------------------
5L正解
------解决方案--------------------
string str = "a,b,c,d,e,f,g,h,i,g,k,j";
       string[] str1 = str.Split(',');
       string strTemp = "";
       for (int i = 0; i < 5; i++)
       {
           strTemp += str1[i] + ",";
       }
       Label1.Text = strTemp;
------解决方案--------------------
string str="xx,xxx,x,xxx,xxxxxx,xxxxx,xxxxxx,xxxxx,xxxxxxxxx,"
char[] chr=str;
string result="";
for(int i=0;i<str.length;i++)
{
result=result+chr[i];  
if(chr[i]==',')
  {
  i++;
  }
 if(i==5)
   return result;
   
}
------解决方案--------------------
正则
".*?,{5}"
------解决方案--------------------
string[] arr = str.Split(",", 6);