Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to unformat a formatted string, remove new line
Date: Sun, 8 Nov 2009 18:58:11 -0500
Organization: The MathWorks, Inc.
Lines: 33
Message-ID: <hd7lso$74k$1@fred.mathworks.com>
References: <hd2915$8ki$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1257724632 7316 172.31.44.65 (8 Nov 2009 23:57:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 8 Nov 2009 23:57:12 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:583440



"galdoor galdos" <mikesmaps@gmail.com> wrote in message 
news:hd2915$8ki$1@fred.mathworks.com...
> I'm trying to figure out the relationship between strings and formatted 
> strings when it comes to escape characters.  I have a string with a \n new 
> line in it but I can't easily remove the new line with the string replace 
> function (strrep).  Of course I can tokenize and reconstruct the string 
> but is there any way to convert a formatted string variable like 
> myFormattedString back to myString as shown below?

*snip*

>>> strrep(myFormattedString, '\n','bar')
> ans =
>
> foo
> bar         %why was the new line not removed???

Because once you've SPRINTFed the string, the literal string \n is replaced 
with the newline character.  In order to replace the newline character, use 
it in your STRREP call.

myString = 'foo\nbar'
myFormattedString = sprintf(myString)
newline = sprintf('\n')
strrep(myFormattedString, newline, 'bar')

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ