Saturday, June 3, 2023

Re: [vim 9 script] String indexing behavior different from legacy Vim

Hi Bram,

Sorry but,
Out of well indexing,
which is faster ?

1) indexing by bytes -> legacy
2) indexing by characters -> vim9script

Thank you for your answer.
Nicolas
**
Le samedi 3 juin 2023 à 13:12:53 UTC+2, Bram Moolenaar a écrit :

> Legacy Vim script:
>
> let text = 'àbc'
> echo text[2]
>
> Result: 'b'
>
> Vim 9 script:
>
> const text = 'àbc'
> echo text[2]
>
> Result: 'c'
>
> Is the different behavior (counting chars vs bytes?) intentional?

Yes, in Vim9 script the index is in characters. In legacy script it is
in bytes.

The help for this doesn't have it's own tag, I'll add one.
You can find it above ":help vim9-gotchas".

--
hundred-and-one symptoms of being an internet addict:
101. U can read htis w/o ny porblm and cant figur eout Y its evn listd.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/8960a096-de72-4872-8f90-fd130fa9f922n%40googlegroups.com.

No comments: