// 空白(空格、换行、tab)和逗号分隔的字符串,变成用逗号分隔 function getSplitString(str) { var arr = str.split(","); var resources = ""; for (var i = 0; i < arr.length; i++) { var arr1 = arr[i].split(/s+/); for (var j = 0; j < arr1.length; j++) { if (jQuery.trim(arr1[j]) != "") { resources += jQuery.trim(arr1[j]) + ","; } } } return resources; }
上面这个方法百度搜的,可以把类似 1 2 3 4 5,8 转换成 1,2,3,4,5,8
后台In拼接SQL参数化:
//串号 if (!queryParam["IMEI"].IsEmpty()) { hasWhere=strSql.AppendWhereOrAnd(hasWhere, @" A.IMEI IN ("); var arrImei = queryParam["IMEI"].ToString().TrimEnd(','); var imies = arrImei.Split(','); var strImeis = new StringBuilder(); for (int i = 0; i < imies.Length; i++) { strImeis.Append($@"@imei_parm_justOne_{i},"); parameter.Add(DbParameters.CreateDbParameter($@"@imei_parm_justOne_{i}", imies[i].Trim(), DbType.String)); } strSql.Append(strImeis.ToString().TrimEnd(',')); strSql.Append(") "); }