1. Problem with split()
- Posted by CraigWelch 1 month ago
- 424 views
From the documentation:
Example 2:
result = split("John,Middle,Doe", ",",, 2) -- Only want 2 sub-sequences. -- result is {"John", "Middle,Doe"}
My actual result:
result = split("John,Middle,Doe", ",",, 2) -- Only want 2 sub-sequences. -- result is {"John", "Middle", "Doe"}
However:
result = split("John,Middle,Doe", ",",, 1) -- Only want 2 sub-sequences. -- result is {"John", "Middle,Doe"}
In other words, the 'limit' operator needs to be one less than desired / documented.
2. Re: Problem with split()
- Posted by andreasWagner 1 month ago
- 394 views
Hallo
From the documentation:
Example 2:
result = split("John,Middle,Doe", ",",, 2) -- Only want 2 sub-sequences. -- result is {"John", "Middle,Doe"}
My actual result:
result = split("John,Middle,Doe", ",",, 2) -- Only want 2 sub-sequences. -- result is {"John", "Middle", "Doe"}
However:
result = split("John,Middle,Doe", ",",, 1) -- Only want 2 sub-sequences. -- result is {"John", "Middle,Doe"}
In other words, the 'limit' operator needs to be one less than desired / documented.
This has probably been discussed before.
Here: https://openeuphoria.org/forum/m/131078.wc
perhaps good to know:
Phix apparently adheres to the documentation here and is therefore incompatible in this case.
Andreas
3. Re: Problem with split()
- Posted by petelomax 1 month ago
- 308 views
perhaps good to know:
Phix apparently adheres to the documentation here and is therefore incompatible in this case.
Hmm, yeah the Phix version decrements and checks limit before adding each segment whereas the Euphoria code (at least the one I just looked at) adds then checks.
?split("John,Middle,Doe",",",limit:=1) -- {"John,Middle,Doe"}
You could say that's weird, or you could say that Euphoria has no way to specify "zero splits", not that I can think of a case where the latter might be useful, then again to the best of my recollection I've never found any use for limit, at all.
Also, Phix does not add (or count) empty segments and later strip them:
?split("John;;;;;;Middle;Name;Doe",";",limit:=3) -- {"John","Middle","Name;Doe"}
Which is not what you'll get from Euphoria - I'll guess {"John",";;;Middle;Name;Doe"} or thereabouts.
I'd argue that's a bigger concern, in that you asked for three items (or 2 with no delimeters) and only gotten two (or 1) back.
PS I switched from commas to semicolons to get round a glitch in that #.#code text#.# stripped me leading commas.
4. Re: Problem with split()
- Posted by CraigWelch 1 month ago
- 293 views
I'm astonished !
I had no idea that I had reported that all those years ago.
Normally if I find an error in a Euphoria routine, as I did with median(). I correct it in my copy of the code, and also update the manual that I keep on a server. Clearly I did neither in this case.

