我正在尝试检索 ace 编辑器中显示的文本中给定字符串的行号。
- 示例:搜索“foo”
- 返回:[ 4, 5 ]
- 条件:ace编辑器内容中第4、5行包含“foo”字符串
最佳答案
遍历所有行并检查 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
}
关于javascript - 在 Ace 编辑器中检索字符串的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18013109/