public List<string> subStringByCount(string text, int count)
{
int start_index = ;//开始索引
int end_index = count - ;//结束索引 double count_value = 1.0 * text.Length / count;
double newCount = Math.Ceiling(count_value);//向上取整,只有有小数就取整,比如3.14,结果4 List<string> list = new List<string>();
for (int i = ; i < newCount; i++)
{
//如果end_index大于字符长度,则添加剩下字符串
if (end_index > text.Length - )
{
list.Add(text.Substring(start_index));
break;
}
else
{
list.Add(text.Substring(start_index, count)); start_index += count;
end_index += count;
}
}
return list;
}

效果:传入字符串“123456789”,个数传4

返回数组:["1234","5678","9"]

最新文章

  1. uri不能处理结尾为点的url的问题
  2. 应用C#和SQLCLR编写SQL Server用户定义函数
  3. oracle win7下 卸载
  4. Atitit. 获取cpu占有率的 java c# .net php node.js的实现
  5. this prototype 闭包 总结
  6. C# 控件聚焦
  7. Apache Shiro 手册
  8. 用Bootstrap 写了个站点
  9. 12天学好C语言——记录我的C语言学习之路(Day 4)
  10. 九宫重拍(bfs + 康拓展开)
  11. zend framework 初识
  12. BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班
  13. spring注解@service(&quot;service&quot;)括号中的service有什么用
  14. 画布跟js.oop
  15. webMagic解析淘宝cookie 提示Invalid cookie header
  16. SpringBoot入门教程(十)应用监控Actuator
  17. checkpoint NGFW VM安装
  18. centos 6.8下载地址
  19. 微信小程序弹出可填写框两种方法
  20. Go 开源博客平台 Pipe 1.0.0 发布!

热门文章

  1. 堆排序Heapsort的Java和C代码
  2. java8 中 ImageIO 读取 tiff 格式的图片失败
  3. linux系统(centos6)的目录结构
  4. Qt开发经验小技巧11-20
  5. gdb命名记录
  6. idea2019.2激活码到2020.7.1【已失效】,有另外的
  7. MySQL中主键id不连贯重置处理办法
  8. 在laravel框架中使用模板继承来进行更方便的布局
  9. win7系统的CMD窗口切换目录--小计
  10. xorm -Get方法实例