Loading ...
Sorry, an error occurred while loading the content.

40879Re: vim7: changed behavior of split()

Expand Messages
  • A. J. Mechelynck
    Oct 5, 2005
    • 0 Attachment
      Mikolaj Machowski wrote:
      > Dnia środa, 5 października 2005 21:20, A. J. Mechelynck napisał:
      >> split("") returns a list of zero elements
      >> split("asdf") returns a list of one element
      >> split("asdf qwer") returns a list of two elements
      >> split("asdf qwer uiop") returns a list of three elements
      >> split("asdf qwer uiop hjkl") returns a list of four elements
      >> etc.
      >>
      >> Returning a list of one empty element, rather than zero element, _that_
      >> would be "special" and "abnormal" handling. Or else split() should
      >> return an additional empty element at the end of the list in all cases,
      >> but there is no need for that since we can test l(list).
      >
      > OK. I was asking because previously split("") was returning [""].
      >
      > m.


      As was said not very long ago, to get [""], use split("","",1). But beware:

      :echo split("asdf","",1)
      ['asdf']
      :echo split(" asdf","",1)
      ['', 'asdf']
      :echo split("asdf ","",1)
      ['asdf', '']
      :echo split(" asdf ","",1)
      ['', 'asdf', '']

      See ":help split()".

      Best regards,
      Tony.
    • Show all 8 messages in this topic