split empty string

I’m usign S = split( STRING, “,” ) in my code. STRING can be empty “”. In this case spilt returns no array ubound( S ) = -1. If STRING = “,” then ubound( S ) = 1

S = split( “”, “,”) )
ubound( S ) = -1 <-- I expected this to be 0 and S(0) = “”

S = split( “,”, “,”) )
ubound( S ) = 1

Is this by design or a bug?

By design. Your expectation is not correct.

S = split("" , “,”)
ubound(S) = -1 // empty string yields empty array

S = split(“x”, “,”)
ubound(S) = 0 // no match, the entire string is in element 0

S = split(“a,b”, “,”)
ubound(S) = 1 // a match yields 2 strings - “a” and “b”

S = split("," , “,”)
ubound(S) = 1 // same as above but both strings are empty - the source reads

S = split(",a" , “,”) // again, 2 strings - “” and “a”

Thanks Tim
My expectation come from other languages, I just check how VB and Python work.

VB S = split("" , “,”) returns S(0) = “”

Python “”.split(",") returns [’’]

Both return the empty string.
I put a workaround into my code. Just need to remember…

To avoid errors, I routinely add a series of separators to the field to split.

There are bug if we use Split on Cocoa 64-bit.
(https://xojo.com/issue/46043)"]feedback case 46043
This case is marked as a duplicate of report 40702 but I can’t access this case. Does someone know if it’s marked as to be resolve in the future?
Thank you.

Note : I sometimes use Split / Join to read /save tab in text file and it cause trouble.
Note 2 : I don’t know how to give a link to a feedback.

Hi Thomas, the link you gave seems not to be a valid url

[quote=302460:@Thomas ROBISSON] […]
(https://xojo.com/issue/46043)"]feedback case 46043
[…]
[/quote]

Just launch Feedback and enter 46043 in the search box.

The link does work, but you need to have the Feedback app.
You can download the app here:
http://www.xojo.com/download/extras.php

It does not work from Chrome on a PC.

Here is the working link <https://xojo.com/issue/40702>

Thomas : To copy the link, click on the gear at the lower left corner of Feedback, and click “Copy Sharing Link”, then paste that without any additional manipulation in the forum. No need to use the Link feature.

I See, I used Firefox.

Just installing…

Thank you all for your answer. Michel, I can’t access to Feedback Case #40702 because it tell me that it is private or doesn’t exists. Can you access it ? I hope it is marked as “to be resolve in next update” because I can’t compile any of my app in 64-bit as my preferences are not well read (then not well saved after).

40702 is a beta bug report. Mind you about 2015R3 beta, back in September 2015.

[quote]The attached project builds an array, joins it and then splits it.

If you build it as a 32 bit Mac application it works okay. If you build it as a 64 bit Mac application it hangs.[/quote]

Could be related to what you describe.

It has been amended regularly since, the latest December 7.

The only workaround I can think of is to replace Split by your own method, maybe using NthField to fill a new array sequentially. I know it will be slow, but between broken and slow, choice is relatively easy…

The other workaround I can think of is to use a 32 bits helper. Would work in Mac and Windows, not Linux.

Ah ok, 64-bit is in beta that’s why I can’t see Feedback. I don’t understand why Xojo allow simple users (like me) to build in 64-bit but not see feedback about 64-bit.

Write a workaround is possible and won’t be so slow as I use split to read small Tab. But as I can’t see 64-bit feedback, I haven’t any idea of how many bugs remain, then I will wait.
Thanks again for your help.

64 bit Windows should be out of beta very soon.

Usually, though, beta bug reports stay available only to beta testers and Xojo, because they refer to beta versions that are never available to the general public.