Bug 11536 – split optional maxsplit argument

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-17T19:03:23Z
Last change time
2024-12-01T16:19:08Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: phobos#10010 →

Comments

Comment #0 by bearophile_hugs — 2013-11-17T19:03:23Z
In Python str.split method has an optional argument (named maxsplit), the number of times to split: http://docs.python.org/2/library/stdtypes.html#str.split >>> "5 red blue".split() ['5', 'red', 'blue'] >>> "5 red blue".split(" ", 1) ['5', ' red blue'] >>> "5 red blue".split(None, 1) ['5', 'red blue'] >>> "red blue 10".rsplit() ['red', 'blue', '10'] >>> "red blue 10".rsplit(" ", 1) ['red blue ', '10'] >>> "red blue 10".rsplit(None, 1) ['red blue', '10'] It's handy when you have a not uniform string that you want to split partially: >>> t = "20 Walter Bright" >>> n, name = t.split(None, 1) >>> n '20' >>> name 'Walter Bright' I think such optional argument could be useful in Phobos split as well.
Comment #1 by robert.schadek — 2024-12-01T16:19:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10010 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB