在Ace编辑器中检索字符串的行号 [英] Retrieve line number of string in Ace Editor

查看:119
本文介绍了在Ace编辑器中检索字符串的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ace编辑器中显示的文本中检索给定字符串的行号。

I'm trying to retrieve the line number of a given string in the text displayed in the ace editor.


  1. 示例:搜索for foo

  2. 返回:[4,5]

  3. 条件:ace编辑器内容中的第4行和第5行包含 foo string


推荐答案

遍历所有行并检查indexOf

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
}

这篇关于在Ace编辑器中检索字符串的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆