118029Re: Adding items'List to items'List2
- Oct 6, 2010On Wed, 6 Oct 2010, epanda wrote:
> Hi,It's unclear from the description why the result is the way it is.
> I have two Lists:
> let list1=['','','','barfoo']
> let list2=['foo','bar','foobar']
> I would like to obtain this List :
> listResult = ['foo','bar','foobar','barfoo']
> ..without looping manually by for or while around my List.
Does it need to start at the first non-empty item of list1? Or does it
only need to know the length of list2?
If the former: (append non-empty elements of list1 to list2)
let listResult = extend(copy(list2), filter(list1, 'strlen(v:val)'))
:help copy() " only if you need to use list2 again later
:help strlen() " only needed if '0' is a valid item
If the latter: (just append anything beyond the end of list2 from list1)
if len(list1) > len(list2)
let listResult = extend(copy(list2), list1[len(list2):])
:help list-index, then search for 'Sublist'
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
- << Previous post in topic Next post in topic >>