octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #57867] strrep: unexpected substitution behavi


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #57867] strrep: unexpected substitution behavior on a char array
Date: Thu, 20 Feb 2020 13:13:23 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

URL:
  <https://savannah.gnu.org/bugs/?57867>

                 Summary: strrep: unexpected substitution behavior on a char
array
                 Project: GNU Octave
            Submitted by: nrjank
            Submitted on: Thu 20 Feb 2020 06:13:21 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
             Assigned to: None
         Originator Name: Nicholas R Jankowski
        Originator Email: 
             Open/Closed: Open
                 Release: other
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

as discussed on the mailing list [1], when strrep is passed a character array,
as opposed to a single char vector, substitution proceeds columnwise, which is
somewhat counterintuitive.

E.g., as expected:

octave:5> c = ['1 2 3 4 5 6']
c = 1 2 3 4 5 6

octave:6> strrep(c,'1 2', '6 7')
ans = 6 7 3 4 5 6


char array:
octave:7> c = ['1 2 3';'4 5 6']
c =

1 2 3
4 5 6

octave:8> strrep(c,'1 2', '6 7')
ans =

1 2 3
4 5 6

octave:9> strrep(c,'14', '67')
ans = 67  25  36




note that matlab throws an error for a non-vector char array. any arrays must
be string (class) arrays, or cell arrays, on which each string handled as
expected.  Octave doesn't yet have a string class, but it handles cell arrays
compatibly. 

This behavior on char arrays doesn't appear to be documented anywhere. 
Unclear if it's an intended extension beyond matlab, in which case it should
probably be documented better, or should we have this function throw an error
for non-vector char arrays?


[1] https://octave.1599824.n4.nabble.com/Re-line-continuations-tp4695788.html




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57867>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]