Saturday, April 2, 2011

Re: Problems using value returned by external command

On 2/04/11 5:52 PM, ZyX wrote:
> Reply to message «Re: Problems using value returned by external command»,
> sent 10:21:48 02 April 2011, Saturday
> by Gary Johnson:
>
>> As you've figured out, Vim's system() function includes in its
>> return value the newline at the end of the command's output. If you
>> need the result without the newline, use substitute() like this:
>>
>> let x = substitute(system("some command"), "\n", "", "")

> This will remove all newlines, not just at the end.

No, it will remove the first newline, whether it's at the end or not.

> If one knows that command will output newline at the end, then he
> should just use system(...)[:-2].

Yes.

Or if you don't, use "\n$" as the pattern. Slower, but will only catch
an end-of-string newline and only if it exists.

Ben.

--
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

No comments: