[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: strsplit
From: |
Benjamin Abbott |
Subject: |
Re: strsplit |
Date: |
Fri, 06 Jun 2014 06:43:14 -0400 |
> On Jun 6, 2014, at 2:58 AM, Juan Pablo Carbajal <address@hidden> wrote:
>
>> On Fri, Jun 6, 2014 at 2:13 AM, Ben Abbott <address@hidden> wrote:
>>> On Jun 5, 2014, at 8:04 PM, Juan Pablo Carbajal <address@hidden> wrote:
>>>
>>>> On Fri, Jun 6, 2014 at 2:01 AM, Mike Miller <address@hidden> wrote:
>>>>> On Fri, Jun 6, 2014 at 01:05:53 +0200, Juan Pablo Carbajal wrote:
>>>>> Hi,
>>>>>
>>>>> Is the following behavior correct in strsplit?
>>>>>
>>>>> strsplit("/usr/local/share/octave/",filesep())
>>>>> ans =
>>>>> {
>>>>> [1,1] =
>>>>> [1,2] = usr
>>>>> [1,3] = local
>>>>> [1,4] = share
>>>>> [1,5] = octave
>>>>> [1,6] =
>>>>> }
>>>>>
>>>>> strsplit("/usr/local/share/octave/",filesep(),true)
>>>>> ans =
>>>>> {
>>>>> [1,1] =
>>>>> [1,2] = usr
>>>>> [1,3] = local
>>>>> [1,4] = share
>>>>> [1,5] = octave
>>>>> [1,6] =
>>>>> }
>>>>>
>>>>> strsplit("/usr/local/share/octave/",filesep(),false)
>>>>> ans =
>>>>> {
>>>>> [1,1] =
>>>>> [1,2] = usr
>>>>> [1,3] = local
>>>>> [1,4] = share
>>>>> [1,5] = octave
>>>>> [1,6] =
>>>>> }
>>>>>
>>>>>
>>>>> The output puts an empty cell element when the matching delimiter is
>>>>> at the beginning and at the end.
>>>>> This causes geometry ADD_PKG script to fail, so the behavior changed
>>>>> not long ago (I remember some mails about this, ml compatibility?).
>>>>
>>>> I see the same behavior in 3.4.3, 3.6.4, and 3.8.1 for this example.
>>>> See also the ostrsplit function in 3.8 which operates like the old
>>>> strsplit.
>>>>
>>>> Anyway, according to bug #39010 [1], it looks like yes, a string that
>>>> begins and ends with the delimiter should return an empty string from
>>>> both ends.
>>>>
>>>> [1] https://savannah.gnu.org/bugs/?39010
>>>>
>>>> --
>>>> mike
>>>
>>> Thank you fro the quick response and the tests.
>>>
>>> ok, I guess this is hereditary disease (or can anybody justify this
>>> behavior?).
>>> If the behavior is so old I wonder how I wasn't getting the failure before.
>>> Anyways I replaced the use of strsplit with fullfile, hopefully this
>>> is more robust and portable.
>>
>> The commands in Matlab would be ...
>>
>> strsplit('/usr/local/share/octave/',filesep())
>>
>> strsplit('/usr/local/share/octave/',filesep(),'CollapseDelimiters',true)
>>
>> strsplit('/usr/local/share/octave/',filesep(),'CollapseDelimiters',false)
>>
>> The third arg for Octave is being taken to be equivalent to Matlab's
>> "CollapseDelimiters" parameter.
>>
>> Perhaps Octave's third arg can be made equivalent to "IgnoreEmpties" instead
>> of "CollapseDelimiters"?
>>
>> In any event, the old version of strsplit() is still present, but was
>> renamed.
>>
>> ostrsplit('/usr/local/share/octave/',filesep(),true)
>> ans =
>> {
>> [1,1] = usr
>> [1,2] = local
>> [1,3] = share
>> [1,4] = octave
>> }
>>
>> Ben
>
> Thank you Ben,
> As far as I can see there is no mention of the parameter
> "IgnoreEmpties" in the help of strsplit. Is this already implemented
> or is it a missing feature?
It is only a suggested change.
Ben
- strsplit, Juan Pablo Carbajal, 2014/06/05