Project

General

Profile

Actions

Feature #21552

closed

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

Feature #21552: allow String.strip and similar to take a parameter similar to String.delete
4

Added by MSP-Greg (Greg L) 5 months ago. Updated about 1 month ago.

Status:
Closed
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.


Related issues 1 (1 open0 closed)

Related to Ruby - Feature #7845: Strip doesn't handle unicode space characters in ruby 1.9.2 & 1.9.3 (does in 1.9.1)OpenActions

Updated by Dan0042 (Daniel DeLorme) 4 months ago 1Actions #1 [ruby-core:123233]

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" 😦

Updated by mame (Yusuke Endoh) about 2 months ago Actions #2

  • Related to Feature #7845: Strip doesn't handle unicode space characters in ruby 1.9.2 & 1.9.3 (does in 1.9.1) added

Updated by shugo (Shugo Maeda) about 1 month ago 1Actions #3 [ruby-core:124019]

I just heard someone ask for a strip function that doesn't remove NUL characters.
Since Python's str.strip takes an optional argument, it might be a good idea to introduce a similar feature.

I've created a pull request at