Retrieve line number of string in Ace Editor

心已入冬 提交于 2019-12-04 09:19:54

Iterate over all lines and check indexOf

function findFooLineNumbers(editor, foo) {
    var lines = editor.session.doc.getAllLines()
    var fooLineNumbers = []
    for (var i = 0, l = lines.length; i < l; i++) {
        if (lines[i].indexOf(foo) != -1)
           fooLineNumbers.push(i)
    }
    return fooLineNumbers
}

You left too little information and you can not expect a great help

If you want to return more information at the same time u need Array

var number = new Number(5) // Single number. he will return just 5

You can try somthing like this to see how to return array

function test() {
    var IDs = new Array();
        IDs['s'] = "1 342 364,586";
        IDs['g'] = "123 324 646 876";

        for (var i = 0; i <= IDs.lenght; i ++ ) {
             // do somthing  
        }
    return IDs;
}

To check if return is realy nubmer use Number.NaN

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!