Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
catching \n (newline)

Subject: catching \n (newline)

From: Naor Movshovitz

Date: 20 Aug, 2007 22:33:06

Message: 1 of 5

sorry about the stupid question but,

>> a=sprintf('\n');
>> strcmp(a,'\n')

ans =

     0

and i don't see anything in the help for strcmp.

Thanks,
-naor

Subject: catching \n (newline)

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 20 Aug, 2007 23:31:06

Message: 2 of 5

In article <fad4r2$m0a$1@fred.mathworks.com>,
Naor Movshovitz <lazy_n@yahoo.com> wrote:
>sorry about the stupid question but,

>>> a=sprintf('\n');
>>> strcmp(a,'\n')

>ans =
>
> 0

>and i don't see anything in the help for strcmp.

In the *printf() I/O functions, \n is a special token sequence
representing newline. In most other places in matlab, \n is
a two character sequence, \ and n.

>> a=sprintf('\n');
>> strcmp(a,char(10))

ans =

     1
>> length('\n')

ans =

     2


--
  All is vanity. -- Ecclesiastes

Subject: catching \n (newline)

From: Naor Movshovitz

Date: 21 Aug, 2007 00:08:47

Message: 3 of 5

Thanks.

-naor
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fad87q$leu$1@canopus.cc.umanitoba.ca>...
> In article <fad4r2$m0a$1@fred.mathworks.com>,
> Naor Movshovitz <lazy_n@yahoo.com> wrote:
> >sorry about the stupid question but,
>
> >>> a=sprintf('\n');
> >>> strcmp(a,'\n')
>
> >ans =
> >
> > 0
>
> >and i don't see anything in the help for strcmp.
>
> In the *printf() I/O functions, \n is a special token
sequence
> representing newline. In most other places in matlab, \n
is
> a two character sequence, \ and n.
>
> >> a=sprintf('\n');
> >> strcmp(a,char(10))
>
> ans =
>
> 1
> >> length('\n')
>
> ans =
>
> 2
>
>
> --
> All is vanity. --
Ecclesiastes

Subject: catching \n (newline)

From: Yair Altman

Date: 21 Aug, 2007 12:28:32

Message: 4 of 5

> >>> a=sprintf('\n');
> >>> strcmp(a,'\n')

replace with: strcmp(a,sprinf('\n'));

Note: this is a platform-independent solution, that takes
care of Unix (\n=char(10)), PCs (\n=[char(10),char(13)]) and
Macs (\n=char(13)). Don't use char(10),char(13) unless
you're certain about your intended platform. FYI, you can
get your system's line separator using the following:

double(char(java.lang.System.getProperty('line.separator')))

Yair Altman
http://ymasoftware.com

Subject: catching \n (newline)

From: Naor Movshovitz

Date: 21 Aug, 2007 19:54:54

Message: 5 of 5

Even better, thanks Yair.

-naor
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<faelpg$j2d$1@fred.mathworks.com>...
> > >>> a=sprintf('\n');
> > >>> strcmp(a,'\n')
>
> replace with: strcmp(a,sprinf('\n'));
>
> Note: this is a platform-independent solution, that takes
> care of Unix (\n=char(10)), PCs (\n=[char(10),char(13)])
and
> Macs (\n=char(13)). Don't use char(10),char(13) unless
> you're certain about your intended platform. FYI, you can
> get your system's line separator using the following:
>
> double(char(java.lang.System.getProperty
('line.separator')))
>
> Yair Altman
> http://ymasoftware.com
>

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us