zed icon indicating copy to clipboard operation
zed copied to clipboard

index & slice operators on bytes/strings

Open mccanne opened this issue 5 years ago • 2 comments

expr.Index() should be able to index a bytes type and return a uint8.

It should also be possible to index a string type and return a rune.

(The index operator already works on arrays.)

While we're at it, we can add a slice operator that works with bytes, strings, and arrays.

All the above should be made to work in ZQL.

mccanne avatar Oct 05 '20 05:10 mccanne

Support for slicing in arrays was added in #2099. We'll circle back to add support for the other data types as use cases emerge that make them a priority.

philrz avatar Feb 11 '21 19:02 philrz

Hmm, we have slices working but not simple indexing...

$ echo '"abc"' | zq 'yield this[0]' -
error("missing")
$ echo '"abc"' | zq 'yield this[0:1]' -
"a"

@nwt, this should be easy to address yes?

mccanne avatar May 28 '22 18:05 mccanne