Adding a number argument to ListToArray

Over in Javascript land, they are looking at this option

## python

print('a|b|c|d|e|f'.split('|', 2))

# ['a', 'b', 'c|d|e|f']

Currently, ListToArray() processes the whole string, regardless

We could add a fifth parameter, (name?) specifying number of elements.

  • when positive, the remaining string gets added as the last array element
  • when negative, nothing more happens, only the first N items get added to the array

This would be useful in terms of performance and memory, as well as being useful when processing complex strings

3 Likes

I actually can see some benefits with that
+1

1 Like

@bennadel said on twitter

so I think adding this extra param to ListFirst and ListRest makes sense too

1 Like

Just to add some color to what I mean, I’ll often attempt to split names like:

name = "John Smith Jr.";
firstName = name.listFirst( " " ); // John
lastName = name.listRest( " " ); // Smith Jr.

So, if I could do a split with a count:

name = "John Smith Jr.";
parts = name.listToArray( ... parts = 2 ... ) ; // [ "John", "Smith Jr." ]
firstName = parts[ 1 ];
lastName = parts[ 2 ];

Ironically, this is more work :laughing: but, I just wanted to add color to my tweet.

3 Likes

I pinged the Adobe team about this proposal

1 Like