if (Distribution_Address !="") {
if (Distribution_Address.Trim().Length == 0) { strSql = " 1=1"; } else { int start =0;//设定替换前的字符串长度 int end = 0;//设定替换后的字符串长度 string temptxt = Distribution_Address.Trim(); do { start = temptxt.Length; temptxt = temptxt.Replace(",", ",").Replace(" ", " "); end = temptxt.Length; } while (start != end);//如果替换前后长度变化,则继续替换 string[] tempStr = temptxt.Split(','); strSql += "and ("; foreach (string temp in tempStr) { if (strSql.Trim().Length != 0) strSql += String.Format("(C_Address like '%{0}%')", temp); strSql += "or"; } strSql += " 1=2 )"; } }
转载于:https://www.cnblogs.com/tuosang/archive/2013/03/29/2989286.html