Bug 13632 – Second argument for std.string.strip

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-10-18T10:42:46Z
Last change time
2018-02-01T03:25:28Z
Keywords
pull
Assigned to
Aravinda
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-10-18T10:42:46Z
I suggest to add to std.string.strip a second optional argument as in the Python string method strip: str.strip([chars]) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped: Examples: >>> ' spacious '.strip() 'spacious' >>> "xxxdataxx".strip("x") 'data' >>> 'www.example.com'.strip('cmowz.') 'example' In D you can use a "char pattern" for the second argument.
Comment #1 by greensunny12 — 2018-01-10T14:09:39Z
@Aravinda VK: thanks a lot for taking this. Please don't forget to add a link to your PR here. Otherwise people in the future will have a hard time finding or even being aware of it: https://github.com/dlang/phobos/pull/6023
Comment #2 by hallimanearavind — 2018-01-10T14:25:46Z
(In reply to Seb from comment #1) > @Aravinda VK: thanks a lot for taking this. Please don't forget to add a > link to your PR here. Otherwise people in the future will have a hard time > finding or even being aware of it: > > https://github.com/dlang/phobos/pull/6023 Noted. This is my first patch/bug in D lang community. I will make sure to add PR link in future. Thanks.
Comment #3 by github-bugzilla — 2018-02-01T03:25:27Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/2346990c091e68d0b07ed2fbd41dd865a3251713 Fix issue 13632: Enhancement to std.string.strip Added second argument similar to Python `str.strip` Second argument accepts a string of characters to strip and strips only those characters. Examples: "xyzhello".stripLeft("xyz") == "hello" "helloxy ".stripRight("xy ") == "hello" "xhellox".strip("x") == "hello" Signed-off-by: Aravinda VK <[email protected]> https://github.com/dlang/phobos/commit/8d93656917bb0f301ed07fe9de773f7484987361 Merge pull request #6023 from aravindavk/string_strip_enhancement Fix issue 13632: Enhancement to std.string.strip merged-on-behalf-of: unknown