您的位置:首页 > 其它

将以逗号分隔的id字符串按每20个id截取分组

2018-02-09 09:46 260 查看
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            CommonMethod.ExecuteFunc(_broker => {
                var dt = _broker.ExecuteSQLForDst($@"SELECT deviceid from sm_device where is_deleted=0").Tables[0];
                if (dt.Rows.Count == 0)
                {
                    return;
                }
                else
                {
                    dt = _broker.ExecuteSQLForDst($@"SELECT GROUP_CONCAT(deviceid,'') from sm_device where is_deleted=0").Tables[0];
                    var Ids = dt.Rows[0][0].ToString();
                    for (int i = 0; i < intercept(Ids).Count(); i++) {
                        SearchOprationLog(intercept(Ids)[i]);
                    }
                }
            }, ex => {
                Console.Write(ex.Message);
            });
            
        }
//将以逗号分隔的id字符串按每20个id截取分组存进list中并返回
public List<string> intercept(string a) {
String[] b = a.Split(',');
int splitLength = 20;
int start = 0;
int end = start + splitLength;
List<string> idList = new List<string>();
while (end < b.Length)
{
StringBuilder builder = new StringBuilder();
for (int i = start; i < end; i++)
{
builder.Append(b[i] + ",");
}
String str = builder.ToString();
String c = str.Substring(0, str.LastIndexOf(","));
idList.Add(c);
start = end;
end = end + splitLength;
}
if (start <= b.Length)
{
StringBuilder builder = new StringBuilder();
for (int i = start; i < b.Length; i++)
{
builder.Append(b[i] + ",");
}
String c = builder.ToString().Substring(0, builder.ToString().LastIndexOf(","));
idList.Add(c);
}
return idList;
}
//查询操作记录接口
public void SearchOprationLog(string deviceIds) {
}




转自http://blog.csdn.net/lvyuan1234/article/details/77511450
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: