我正在编写我的第一个程序,我发现它运行缓慢。它用于将一种文本格式转换为另一种格式。这样做时,我经常需要搜索某个字符串,然后从那里解析文本。这可能看起来像:
const string separator = "Parameters Table";
// Get to the first separator
var cuttedWords = backgroundWords.SkipWhile(x => x != separator).Skip(1);
// Run as long as there is anything left to scan
while (cuttedWords.Any())
{
// Take data from the last found separator until the next one, exclusively
var variable = cuttedWords.TakeWhile(x => x != separator).ToArray();
// Step through cuttedWords to update where the last found separator was
cuttedWords = cuttedWords.Skip(variable.Length + 1);
// Do what you want with the sub-array containing information
}
我想知道是否有更有效的方法来做同样的事情(即搜索一个字符串并使用该字符串和下一个相同字符串之间的子数组执行我想要的操作)。谢谢你。