Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support string indexing to yield substrings #243

Closed
xiaq opened this issue Oct 9, 2016 · 1 comment
Closed

Support string indexing to yield substrings #243

xiaq opened this issue Oct 9, 2016 · 1 comment

Comments

@xiaq
Copy link
Member

xiaq commented Oct 9, 2016

If s=hello, s[0] is h, s[-1] is o, and s[1:4] is ell.

For strings containing multi-byte codepoints, we can copy Julia, i.e.

  • Indexing yields codepoints instead of bytes.
  • Indices are byte indices.

For instance, if s=你好 (Chinese codepoints occupy 3 bytes in UTF-8), s[0] is , s[3] is . Indexing at other indices throws an error.

We need to give up the current behavior of string indexing. Right now s[a b] is equivalent to (s a b). I suppose that one syntax for command substitution is enough.

@xiaq xiaq added this to the 1.0 milestone Oct 9, 2016
@xiaq xiaq closed this as completed in ad5a74d Oct 9, 2016
@xiaq
Copy link
Member Author

xiaq commented Oct 9, 2016

In addition to indexing, iteration is supported as well, meaning that splicing is also supported:

s=你好
put $@s | each echo
#
#

huiyiqun pushed a commit to huiyiqun/elvish that referenced this issue Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant