Reputation: 1704
I'm trying to retrieve the line number of a given string in the text displayed in the ace editor.
Upvotes: 7
Views: 3991
Reputation: 85
In short:
var found = editor.$search.find(editor.getSession());
More on this on https://www.debugcn.com/en/article/12331736.html
Upvotes: 0
Reputation: 24104
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
}
Upvotes: 6
Reputation: 5248
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
Upvotes: -1