bearophile_hugs reported this on 2013-11-17T19:03:23Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=11536
Description
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.