Issue #14783 has been updated by shevegen (Robert A. Heiler).


Is the frequency of #bytes_at common? I understand the use case
stated by Stefan (extract multiple indices via one method call
on a String) but #bytes_at may seem to be quite rare.

As for returning a String or Array, I personally expect #chars
on a String object to return an Array, so intuitively I would
assume #chars_at to also return an Array.

----------------------------------------
Feature #14783: String#chars_at / String#bytes_at
https://bugs.ruby-lang.org/issues/14783#change-72242

* Author: sos4nt (Stefan Schler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I just wanted to extract characters at certain indices from a string and noticed that there's no `values_at` counterpart for `String`.

I'd therefore like to propose two new `String` methods:

* `chars_at(selector, ...) вк new_str`
* `bytes_at(selector, ...) вк new_str`

which work basically like [`Array#values_at`](http://ruby-doc.org/core/Array.html#method-i-values_at), e.g.:

```ruby
string = 'hello, world!'
string.chars_at(0, 5, 7, 12)  #=> "h,w!" 
string.chars_at(0..4, 7..11)  #=> "helloworld" 
```





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>