string.Concat("1,2,3,4,5,6,7,,,,,,".Split(','))
1.方法一:
string [] strs = reques[''XXX"].Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
string strtemp = string.empty;
for(int i=0;i<strs.length;i++)
{
if(i!=strs.length-1)
{
strtemp = strtemp+strs[i]+",";
}
else
{
strtemp = strtemp+strs[i];
}
}
2.方法2:使用.Net内置函数
string a = string.Join(",",Request.Form["XXX"].Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries))
备注:
例子代码中没有考虑非空情况,请自行考虑。
'
考虑到可能还会输入逗号,所以最好用Request.Form.GetValues("XXX")来取值
然后用string.IsNullOrEmpty逐个判断,取出非空元素~
string[] strs = Request["XXX"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string newstrs = string.Join(',', strs);