Project

General

Profile

Actions

Feature #14783

open

String#chars_at / String#bytes_at

Added by sos4nt (Stefan Schüßler) over 6 years ago. Updated over 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:87235]

Description

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, e.g.:

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0