News:

MultiCommander v16.6 is released!

Main Menu

Multiscript StrSplit improve

Started by Jungle, December 09, 2022, 14:37:47

Previous topic - Next topic

Jungle

Now delimiter param in StrSplit function is used as a single separator. It means that the following code will not split input string

@var $str = "123,|456;|,789";
@var $arr = StrSplit($str, ";|,");


I request additional optional param like any_char (0/1):
- with the value 0 the function would have current behaviour;
- with the value 1 the character of the delimiter which has the lowest index in the input string would be used as a delimiter (so in the code above it would be "," char)
- with the value 2 the first found char of the delimiter would be used as a delimiter (so in the code above it would be "|" char)

Mathias (Author)

I think I rather add a new split function for it

StrSplitAny($str , ";|." );

Is Option 2 really needed ? if you enter many delimiters . dont you always want it to split at the position where any of the delimiters are found ? (option 1 ?)



Jungle

#2
Quote from: Mathias (Author) on December 10, 2022, 14:31:43Is Option 2 really needed ? if you enter many delimiters . dont you always want it to split at the position where any of the delimiters are found ? (option 1 ?)

Actually, there may also be 3 option :) The first char of the delimiter param would be the delimiter (";" in the code above). If not found, then the second one etc. So:
- 1st from the input string disregarding delimiters order
- 1st from the input string regarding delimiters order
- 1st from the delimiter string disregarding input string index

Mathias (Author)

Quote from: Jungle on December 10, 2022, 17:20:26
Quote from: Mathias (Author) on December 10, 2022, 14:31:43Is Option 2 really needed ? if you enter many delimiters . dont you always want it to split at the position where any of the delimiters are found ? (option 1 ?)

Actually, there may also be 3 option :) The first char of the delimiter param would be the delimiter (";" in the code above). If not found, then the second one etc. So:
- 1st from the input string disregarding delimiters order
- 1st from the input string regarding delimiters order
- 1st from the delimiter string disregarding input string index

Yes I Know but I find the other case strange. and wonder how useful it really is. adding something just because it can be added is not time well spent.
looking around at split function in other places I find the "Split where the first of ANY of the specified delimiters is found.."  But I can't find any uses for the other options.