Search code examples
linuxoctavespacesstrcat

Octave strcat ignores added spaces


Octave adds spaces with strcat

In Octave I run these commands:

strcat ("hel", " ", "lo") 

I get this result:

ans = hello

Instead of what I expected:

ans = hel lo

strcat to me sounds like "concatenate strings". A space is a valid character, so adding a space should be OK. Matlab has the same behaviour, so it's probably intended.

I find it counter intuitive. Does this behavior makes sense?


Solution

  • Hmm. It works how it is defined:

    "strcat removes trailing white space in the arguments (except within cell arrays), while cstrcat leaves white space untouched. "

    From http://www.gnu.org/software/octave/doc/interpreter/Concatenating-Strings.html

    So the question could be: Should this behaviour be changed.