|
From: | Brett Green |
Subject: | Re: input with line break |
Date: | Sun, 6 Oct 2019 11:30:40 -0400 |
Thanks, Przemek. I didn't know.
I read in 'Free your numbers'
5.1 Escape Sequences in String Constants
In double-quoted strings, the backslash character is used to introduce
escape sequences that
represent other characters. For example, ‘\n’ embeds a newline character
in a double-quoted
string and ‘\"’ embeds a double quote character. In single-quoted
strings, backslash is not
a special character.
I read in 'help fprintf':
Implementation Note: For compatibility with MATLAB, escape
sequences in the template string (e.g., "\n" => newline) are
expanded even when the template string is defined with single
quotes.
It's a little confused for me, I don't understand why single and double
quoted string are different. I don't understand what is the objective or
the advantage of this difference.
Regards
Santiago Higuera
El 4/10/19 a las 22:00, Przemek Klosowski via Help list for GNU Octave
escribió:
> On 10/3/19 5:12 PM, Santiago Higuera wrote:
>> Hi all:
>>
>> I'm using Ocatve 5.1, and I've observed that if I use:
>>
>> x=input("x= \n")
>>
>> The special character '\n' is recognized, but if I use single quoted
>> string, it is not recognized.
>>
>> Is it a bug? In MATLAB single quoted string recognize the special
>> character for line break in input() function.
>
> I don't consider it a bug---it's a convention used in many other
> places (e.g. the shell)
>
> Matlab disregards escape characters in both forms, but seems to
> special-case escape characters (at least \n) in input(). Octave
> doesn't need to because you can pass them in double-quoted strings.
>
> It is a minor Octave-Matlab incompatibility but I just think Octave
> does it better. Are there other known cases of special-casing escapes
> in Matlab?
>
>
>
[Prev in Thread] | Current Thread | [Next in Thread] |