Net-informations.com
SiteMap  | About    

StringWriter and StringReader

StringWriter Class Implements a TextWriter for writing information to a string and the information is stored in an underlying StringBuilder Class. StringBuilder Class Represents a mutable string of characters and this class cannot be inherited.

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

  Dim stringWriter As New StringWriter()
  stringWriter.WriteLine("vb.net-informations.com")

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

  Dim message As String
  Dim stringReader As New StringReader(String)

The next line from the underlying string, or Nothing if the end of the underlying string is reached.

The following program shows how to use StringWriter and StringReader Classes in VB.NET.




Imports System.IO
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim stringWriter As New StringWriter()
		stringWriter.WriteLine("net-informations.com")
		stringWriter.WriteLine("vb.net-informations.com")
		stringWriter.WriteLine("csharp.net-informations.com")

		MsgBox(stringWriter.ToString)

		Dim singleLine As String
		Dim message As String
		Dim stringReader As New StringReader(stringWriter.ToString)
		While True
			singleLine = stringReader.ReadLine
			If singleLine Is Nothing Then
				Exit While
			Else
				message = message & singleLine & Environment.NewLine
			End If
		End While

		MsgBox(message)
	End Sub
End Class






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