<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: C# Convert String to Stream, and Stream to String</title>
	<atom:link href="http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/</link>
	<description>C# Information, Code, Tips and News</description>
	<lastBuildDate>Thu, 09 Sep 2010 19:15:17 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: timm</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-5401</link>
		<dc:creator>timm</dc:creator>
		<pubDate>Fri, 12 Mar 2010 18:49:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-5401</guid>
		<description>@krishna: Use the Join method on the String class.  For example, to join the array of strings with a newline between each string:

int count = 100;
string[] strings = new string[count]
for (int i = 0; i &lt; count; i++)
   strings[i] = i.ToString();
string joined = String.Join( &quot;\n&quot;, strings );</description>
		<content:encoded><![CDATA[<p>@krishna: Use the Join method on the String class.  For example, to join the array of strings with a newline between each string:</p>
<p>int count = 100;<br />
string[] strings = new string[count]<br />
for (int i = 0; i < count; i++)<br />
   strings[i] = i.ToString();<br />
string joined = String.Join( "\n", strings );</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: krishna</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-5400</link>
		<dc:creator>krishna</dc:creator>
		<pubDate>Fri, 12 Mar 2010 07:55:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-5400</guid>
		<description>hi ...

I want to convert an array of string to a normal string variable.... can anyone give me the code....

eg :

string[] final should be converted to string fin....</description>
		<content:encoded><![CDATA[<p>hi &#8230;</p>
<p>I want to convert an array of string to a normal string variable&#8230;. can anyone give me the code&#8230;.</p>
<p>eg :</p>
<p>string[] final should be converted to string fin&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frozzeg</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-5398</link>
		<dc:creator>Frozzeg</dc:creator>
		<pubDate>Fri, 05 Mar 2010 13:44:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-5398</guid>
		<description>easy and helpful, thx)</description>
		<content:encoded><![CDATA[<p>easy and helpful, thx)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ctford</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-5249</link>
		<dc:creator>ctford</dc:creator>
		<pubDate>Tue, 04 Aug 2009 18:51:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-5249</guid>
		<description>@AndrewSeven Using a MemoryStream and StreamWriter doesn&#039;t get around choosing an encoding. You have to have an encoding to express a string in bytes.

The StreamWriter constructor uses the &quot;the default encoding and buffer size&quot; if they are not specified (see http://msdn.microsoft.com/en-us/library/aa328965%28VS.71%29.aspx).

By using a MemoryStream and StreamWriter you aren&#039;t avoiding choosing an encoding, just making it implicit rather than explicit.</description>
		<content:encoded><![CDATA[<p>@AndrewSeven Using a MemoryStream and StreamWriter doesn't get around choosing an encoding. You have to have an encoding to express a string in bytes.</p>
<p>The StreamWriter constructor uses the "the default encoding and buffer size" if they are not specified (see <a href="http://msdn.microsoft.com/en-us/library/aa328965%28VS.71%29.aspx)" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa328965%28VS.71%29.aspx)</a>.</p>
<p>By using a MemoryStream and StreamWriter you aren't avoiding choosing an encoding, just making it implicit rather than explicit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AndrewSeven</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-4451</link>
		<dc:creator>AndrewSeven</dc:creator>
		<pubDate>Fri, 20 Mar 2009 19:38:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-4451</guid>
		<description>Thanks,

There is a little more code when using the memory stream however it does not require you to know the encoding whereas using GetBytes requires you to know the encoding ahead of time</description>
		<content:encoded><![CDATA[<p>Thanks,</p>
<p>There is a little more code when using the memory stream however it does not require you to know the encoding whereas using GetBytes requires you to know the encoding ahead of time</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timm</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-4195</link>
		<dc:creator>timm</dc:creator>
		<pubDate>Fri, 20 Feb 2009 14:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-4195</guid>
		<description>Yes, you can also use StreamWriter, which as you say provides more symmetry, though also more code.  You need to call Flush() to complete the write, and you also need to reset the Stream position to zero when starting the read.  Here is the modified code:

string test = &quot;Testing 1-2-3&quot;;

// convert string to stream
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter( stream );
writer.Write( test );
writer.Flush();

// convert stream to string
stream.Position = 0;
StreamReader reader = new StreamReader( stream );
string text = reader.ReadToEnd();</description>
		<content:encoded><![CDATA[<p>Yes, you can also use StreamWriter, which as you say provides more symmetry, though also more code.  You need to call Flush() to complete the write, and you also need to reset the Stream position to zero when starting the read.  Here is the modified code:</p>
<p>string test = "Testing 1-2-3&#8243;;</p>
<p>// convert string to stream<br />
MemoryStream stream = new MemoryStream();<br />
StreamWriter writer = new StreamWriter( stream );<br />
writer.Write( test );<br />
writer.Flush();</p>
<p>// convert stream to string<br />
stream.Position = 0;<br />
StreamReader reader = new StreamReader( stream );<br />
string text = reader.ReadToEnd();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-4194</link>
		<dc:creator>Tony</dc:creator>
		<pubDate>Fri, 20 Feb 2009 13:26:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-4194</guid>
		<description>just what I needed...thx
:-))</description>
		<content:encoded><![CDATA[<p>just what I needed&#8230;thx<br />
 <img src='http://www.csharp411.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/comment-page-1/#comment-4192</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Fri, 20 Feb 2009 08:08:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.csharp411.com/c-convert-string-to-stream-and-stream-to-string/#comment-4192</guid>
		<description>How about using a StreamWriter instead of Encoding? That would really mirror your use of StreamReader, and it would be more efficient when not working with in-memory streams.</description>
		<content:encoded><![CDATA[<p>How about using a StreamWriter instead of Encoding? That would really mirror your use of StreamReader, and it would be more efficient when not working with in-memory streams.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
