一个长字符串,每30个截取一次,形成一个数组,各位大神救命啊。
2 回答
侃侃尔雅
TA贡献1801条经验 获得超16个赞
static IEnumerable<string> Split(string str, int chunkSize)
{ return Enumerable.Range(0, str.Length / chunkSize)
.Select(i => str.Substring(i * chunkSize, chunkSize));
}这个自己随便写写好了,你需要多快?
这上面的代码是有问题的,你自己改改。。。
不负相思意
TA贡献1777条经验 获得超10个赞
static string[] SplitByLength(string source, int length)
{
List<string> result = new List<string>(); int i = 0; int rest = source.Length; while (i < source.Length && rest > length)
{
result.Add(source.Substring(i, length));
i += length;
rest -= length;
}
result.Add(source.Substring(i, rest)); return result.ToArray();
}- 2 回答
- 0 关注
- 828 浏览
添加回答
举报
0/150
提交
取消
