www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11536] New: split optional maxsplit argument

https://d.puremagic.com/issues/show_bug.cgi?id=11536

           Summary: split optional maxsplit argument
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 17 2013