1. Problem with split()

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.

new topic     » topic index » view message » categorize

2. Re: Problem with split()

Hallo

CraigWelch said...

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: Problem with split()

andreasWagner said...

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.

Phix said...
?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:

Phix said...
?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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Problem with split()

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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu