maxsplit parameter for StrSplit Topic is solved

Propose new features and changes
GeekDude
Posts: 843
Joined: 02 Oct 2013, 22:13

maxsplit parameter for StrSplit

24 Mar 2015, 16:23

Similar to python's str.split's parameter.
Python's docs wrote:If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).
As for a use case example:

Code: Select all

Input = 
(
This = ini
Foo = Bar = Baz
)

Out := []
for each, Line in StrSplit(Input, "`n", "`r")
{
	Split := StrSplit(Line, "=",, 2)
	Out[Trim(Split.1)] := Trim(Split.2)
}

Msgbox, % Out.Foo ; Should be "Bar = Baz"
lexikos
Posts: 6176
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: maxsplit parameter for StrSplit

31 Dec 2017, 00:05

This is simple to implement, but are we sure the Python way is the most intuitive?

For instance, I would probably want "at most n substrings" rather than "at most n splits|n+1 substrings", which means I would have to do mental math when using the function or reading the code.
GeekDude
Posts: 843
Joined: 02 Oct 2013, 22:13

Re: maxsplit parameter for StrSplit

31 Dec 2017, 10:09

I agree, and though I don't remember making this request it appears I thought the same thing at the time. The sample code I shared in the original post uses 2 as its max split parameter, in order to split the string into a max of two parts.

In python, you'd have to specify 1 to split into two parts.
lexikos
Posts: 6176
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: maxsplit parameter for StrSplit  Topic is solved

13 Jan 2018, 20:02

The preview of v1.1.28.00 adds a MaxParts parameter.

Edit: v1.1.28.00 has been released.
Last edited by lexikos on 10 Feb 2018, 21:34, edited 1 time in total.
Reason: see above

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 5 guests