代码之家  ›  专栏  ›  技术社区  ›  Arafat Hasan

vim脚本中的子字符串

  •  7
  • Arafat Hasan  · 技术社区  · 7 年前

    有吗 substr() 像函数在vim脚本中获取子字符串?如果不是,这类任务的最佳替代品或替代品是什么?

    3 回复  |  直到 7 年前
        1
  •  10
  •   Kent    7 年前

    echo '0123456'[2:4]
    234
    

    :h expr-[:]
    
        2
  •  3
  •   Luc Hermitte    7 年前

    :h strcharpart()

    function! lh#encoding#strpart(mb_string, p, l)
      " call lh#assert#value(lh#encoding#strlen(a:mb_string)).is_ge(a:p+a:l)
      return matchstr(a:mb_string, '.\{,'.a:l.'}', 0, a:p+1)
    endfunction
    
        3
  •  2
  •   Uprooted    7 年前

    b e str[b:e]

    str[byteidx(str,b):byteidx(str,e+1)-1]