Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

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

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
strcmp Naor Movshovitz 20 Aug, 2007 18:35:18
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics