<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265210</link>
    <title>MATLAB Central Newsreader - How to unformat a formatted string, remove new line</title>
    <description>Feed for thread: How to unformat a formatted string, remove new line</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 06 Nov 2009 22:47:01 -0500</pubDate>
      <title>How to unformat a formatted string, remove new line</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265210#692814</link>
      <author>galdoor galdos</author>
      <description>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?&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; myString = 'foo\nbar'&lt;br&gt;
myString =&lt;br&gt;
&lt;br&gt;
foo\nbar&lt;br&gt;
&amp;gt;&amp;gt; myFormattedString = sprintf('%s',myString)&lt;br&gt;
myFormattedString =&lt;br&gt;
&lt;br&gt;
foo\nbar&lt;br&gt;
&amp;gt;&amp;gt; myFormattedString = sprintf(myString)&lt;br&gt;
myFormattedString =&lt;br&gt;
&lt;br&gt;
foo&lt;br&gt;
bar&lt;br&gt;
&amp;gt;&amp;gt; strrep(myFormattedString, 'foo','bar')&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
bar&lt;br&gt;
bar&lt;br&gt;
&amp;gt;&amp;gt; strrep(myFormattedString, '\n','bar')&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
foo&lt;br&gt;
bar         %why was the new line not removed???&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
thanks,&lt;br&gt;
Mike</description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 23:58:11 -0500</pubDate>
      <title>Re: How to unformat a formatted string, remove new line</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265210#693106</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;galdoor galdos&quot; &amp;lt;mikesmaps@gmail.com&amp;gt; wrote in message &lt;br&gt;
news:hd2915$8ki$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; I'm trying to figure out the relationship between strings and formatted &lt;br&gt;
&amp;gt; strings when it comes to escape characters.  I have a string with a \n new &lt;br&gt;
&amp;gt; line in it but I can't easily remove the new line with the string replace &lt;br&gt;
&amp;gt; function (strrep).  Of course I can tokenize and reconstruct the string &lt;br&gt;
&amp;gt; but is there any way to convert a formatted string variable like &lt;br&gt;
&amp;gt; myFormattedString back to myString as shown below?&lt;br&gt;
&lt;br&gt;
*snip*&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; strrep(myFormattedString, '\n','bar')&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; foo&lt;br&gt;
&amp;gt; bar         %why was the new line not removed???&lt;br&gt;
&lt;br&gt;
Because once you've SPRINTFed the string, the literal string \n is replaced &lt;br&gt;
with the newline character.  In order to replace the newline character, use &lt;br&gt;
it in your STRREP call.&lt;br&gt;
&lt;br&gt;
myString = 'foo\nbar'&lt;br&gt;
myFormattedString = sprintf(myString)&lt;br&gt;
newline = sprintf('\n')&lt;br&gt;
strrep(myFormattedString, newline, 'bar')&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
  </channel>
</rss>

