I'm trying to retrieve the line number of a given string in the text displayed in the ace editor.
- Example: searching for "foo"
- Return: [ 4, 5 ]
- Condition: Line 4 and 5 in the content of the ace editor contains the "foo" string
I'm trying to retrieve the line number of a given string in the text displayed in the ace editor.
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
}
In short:
var found = editor.$search.find(editor.getSession());
More on this on https://www.debugcn.com/en/article/12331736.html
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