Project

General

Profile

Actions

Feature #21552

open

allow String.strip and similar to take a parameter similar to String.delete

Added by MSP-Greg (Greg L) 21 days ago. Updated 1 day ago.

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

Description

Regrading String.strip (and lstrip, rstrip, and ! versions)

Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both.

It would be helpful if they had an optional parameter similar to String.delete with a one multi-character selector, so one could do:

t = str.strip " \t"

One can use a regex for this, but this much simpler.

Updated by Dan0042 (Daniel DeLorme) 1 day ago

Agreed. I tend to use str.sub(/[\ \t]+\z/,'') for this, but an end-anchored regexp has pretty bad worst-case performance. Try to benchmark the previous when str = " "*1000+"a" đŸ˜Ļ

Actions

Also available in: Atom PDF

Like2
Like0