迭代NodeJS中的字符串行

Tow*_*wer 2 javascript node.js ecmascript-5

我从child_process.exec()NodeJS 得到一个缓冲区(我可以把它变成一个字符串).我需要迭代输出字符串的行.我该怎么做?

650*_*502 10

避免将整个事物分解为内存的一种方法是一次处理一行

var i = 0;
while (i < output.length)
{
    var j = output.indexOf("\\n", i);
    if (j == -1) j = output.length;
    .... process output.substr(i, j-i) ....
    i = j+1;
}
Run Code Online (Sandbox Code Playgroud)