Author Topic: Multiscript StrSplit improve  (Read 15817 times)

Jungle

  • Contributor
  • VIP Member
  • *****
  • Posts: 556
  • Old Skull
    • View Profile
Multiscript StrSplit improve
« on: December 09, 2022, 14:37:47 »
Now delimiter param in StrSplit function is used as a single separator. It means that the following code will not split input string

Code: [Select]
@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)
« Last Edit: December 09, 2022, 14:42:53 by Jungle »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4492
    • View Profile
    • Multi Commander
Re: Multiscript StrSplit improve
« Reply #1 on: December 10, 2022, 14:31:43 »
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

  • Contributor
  • VIP Member
  • *****
  • Posts: 556
  • Old Skull
    • View Profile
Re: Multiscript StrSplit improve
« Reply #2 on: December 10, 2022, 17:20:26 »
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 ?)

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
« Last Edit: December 10, 2022, 17:36:02 by Jungle »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4492
    • View Profile
    • Multi Commander
Re: Multiscript StrSplit improve
« Reply #3 on: December 11, 2022, 11:32:15 »
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 ?)

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.