2011-03-27 36 views

回答

4

:h E714

:let l = len(list)    " number of items in list 
:let list = split("a b c")  " create list from items in a string 

在你的情况,

let string = "3,5,7,19" 
let list = split(string, ",") 
echo len(list) 
+0

@N 1.1,非常感谢哟。我也查过:h E714,不知道这个页面 – Reman 2011-03-27 17:03:48

+0

@Rem:HTH。 vim拥有一切文档。 :) – 2011-03-27 17:06:43

2

使用splitlenempty功能:

let list=split(string, ',') 
let list_length=len(list) 
" If all you want is to check whether list is empty: 
if empty(list) 
    throw "You must provide at least one value" 
endif 

请注意,如果你想获得数出字符串的列表,你将不得不使用地图列表元素转换成数字:

let list=map(split(string, ','), '+v:val') 

大多数时候,你可以指望的字符串转化为数字的时间,但有时候这种转变还没有完成。

+0

感谢ZyX的回答。 – Reman 2011-03-27 17:04:20

相关问题