Net-informations.com
SiteMap  | About    

StringWriter StringReader

The string type represents a sequence of zero or more Unicode characters. string is an alias for String in the .NET Framework. The StringWriter Class Implements a TextWriter for writing information to a string and the information is stored in an underlying StringBuilder Class.

WriteLine(String) method writes a string followed by a line terminator to the text stream.

  StringWriter stringWriter = new StringWriter();
   stringWriter.WriteLine("csharp.net-informations.com");

StringReader Class Implements a TextReader that reads from a string. StringReader.ReadLine Method Reads a line from the underlying string.

  stringReader.ReadLine();

The following program shows how to use StringWriter and StringReader Classes in C#.




using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			StringWriter stringWriter = new StringWriter();
			stringWriter.WriteLine("net-informations.com");
			stringWriter.WriteLine("vb.net-informations.com");
			stringWriter.WriteLine("csharp.net-informations.com");

			MessageBox.Show (stringWriter.ToString());

			string singleLine = null;
			string message = null;
			StringReader stringReader = new StringReader(stringWriter.ToString());
			while (true)
			{
				singleLine = stringReader.ReadLine();
				if (singleLine == null)
				{
					break; 
				}
				else
				{
					message = message + singleLine + Environment.NewLine;
				}
			}

			MessageBox.Show (message);
		}
	}
}






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.