将以逗号分隔的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
相关文章推荐
- 将以逗号分隔的id字符串按每20个id截取分组
- MySQL使用GROUP_CONCAT()函数按ID分组将多条记录的某个字段以逗号或者指定分隔号隔开成一条记录
- 截取以逗号分隔的字符串
- 用逗号分隔截取字符串中的值
- 截取以逗号分隔的字符串放到map中
- oracle函数 逗号分隔的字符串的每个字串两边加上单引号
- javascript中及在后台把一个字符串以逗号分隔
- c# 以多个字符串分隔字符串数据 分组 分隔 split 正则分组
- sql将逗号分隔的字符串转为表Table
- 如何相互转换逗号分隔的字符串和List (Java程序员日记 2015/03/06)
- 判断一个数值是否在一个逗号分隔的字符串中
- oracle拆分逗号分隔字符串 实现split
- 【Java面试题】17 如何把一个逗号分隔的字符串转换为数组? 关于String类中split方法的使用,超级详细!!!
- django自定义Field实现一个字段存储以逗号分隔的字符串
- IOS NSString 字符串处理:截取字符串、匹配字符串、分隔字符串
- Matlab 读取dat文件(包含几行多余文本,数据带有数字和字符串,且以逗号分隔)
- 把一个字符串数组转换为一个逗号分隔的字符串
- js 将数组转换为逗号分隔的字符串
- JSTL 字符串以逗号分隔转数组
- 获取指定字符串中的图片地址,逗号分隔