【发布时间】:2016-03-29 13:44:25
【问题描述】:
我已经使用下面的代码来拆分字符串,但是需要很多时间。
using (StreamReader srSegmentData = new StreamReader(fileNamePath))
{
string strSegmentData = "";
string line = srSegmentData.ReadToEnd();
int startPos = 0;
ArrayList alSegments = new ArrayList();
while (startPos < line.Length && (line.Length - startPos) >= segmentSize)
{
strSegmentData = strSegmentData + line.Substring(startPos, segmentSize) + Environment.NewLine;
alSegments.Add(line.Substring(startPos, segmentSize) + Environment.NewLine);
startPos = startPos + segmentSize;
}
}
请建议我另一种方法将字符串拆分成固定大小的小块
【问题讨论】:
-
String.Split可能是一种选择 -
这可能会有所帮助:*.com/questions/568968/…
-
我们没有任何特定的字符可以使用Split,只需要根据大小(字符数)分隔字符串
-
哪位需要很长时间?
srSegmentData.ReadToEnd();或while循环?你真的测量过吗? -
你为什么使用
ArrayList? 10 年前的事了。