【发布时间】:2020-12-08 18:23:40
【问题描述】:
我目前有大型分隔数据集,我需要返回每列的最小\最大长度。 我目前在 Emeditor v20.3 中使用以下代码,效果很好,但我想知道是否有更快的方法,特别是当有数百万行数据和数百列时(并且此代码很慢)。
非常感谢任何可以包装到 javascript 宏中的更快的方法或想法。
for( col = colStart; col <= MaxCol; col++ ) {
sTitle = document.GetCell( 1, col, eeCellIncludeNone );
min = -1;
max = 0;
for( line = document.HeadingLines + 1; line < MaxLines; line++ ) {
str = document.GetCell( line, col, eeCellIncludeQuotesAndDelimiter );
if( min == -1 || min > str.length ) {
min = str.length;
}
if( max < str.length ) {
max = str.length;
}
}
OutputBar.writeln( col + min + " " + max + " " + sTitle);
}
【问题讨论】:
-
您可以使用 Find Longest Line/Cell 命令和 Find Non-Empty Shortest Line/Cell 命令来优化速度。
-
太好了。由于最短返回非空,是否有一种最佳方法可以通过宏检查何时/如果最小长度 = 0?
-
如果最短单元格长度不为零,则可以搜索空单元格。一种方法是在设置
'^' and '$' can Match Beginning and End of the Selection选项时在所选列中搜索^$(正则表达式)。 -
感谢 Yutaka 的提示,我在想这样的事情,但我会做一些测试。如果在未来的版本中可以添加一个方法来只返回最短(包括零),那就太好了。
var noZeroLengthData = document.Filter("",xOrgCell,eeFindWholeString,0,0,0); -
下一个版本 (20.3.906) 将包含 Find Shortest Line/Cell 命令。
标签: performance emeditor