Draft for Information Only
Content
Device I/O StringReader Class Constructors Methods Explicit Interface Implementations Remarks Applies to See also StreamWriter Class Constructors Properties Methods Fields Remarks Applies to See also Examples Source/Reference
Device I/O
The main components used in .NET framework to access the device i/o are Stream ,
BufferedStream , FileStream , MemoryStream , StreamReader , StreamWriter ,
StringReader , StringWriter , TextReader , TextWriter , BinaryReader , and
BinaryWriter .
StringReader Class
Implements a TextReader that reads from a string.
Namespace System.IO
Assemblies System.IO.dll, mscorlib.dll, netstandard.dll, System.Runtime.Extensions.dll
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class StringReader : System.IO.TextReader
Inheritance: Object ->MarshalByRefObject ->TextReader ->StringReader
Attributes: ComVisibleAttribute , SerializableAttribute
Constructors
Methods
Close()
Closes the StringReader .
CreateObjRef(Type)
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject )
Dispose()
Releases all resources used by the TextReader object.
(Inherited from TextReader )
Dispose(Boolean)
Releases the unmanaged resources used by the StringReader and optionally releases the managed resources.
Equals(Object)
Determines whether the specified object is equal to the current object.
(Inherited from Object )
GetHashCode()
Serves as the default hash function.
(Inherited from Object )
GetLifetimeService()
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject )
GetType()
Gets the Type of the current instance.
(Inherited from Object )
InitializeLifetimeService()
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject )
MemberwiseClone()
Creates a shallow copy of the current Object .
(Inherited from Object )
MemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject )
Peek()
Returns the next available character but does not consume it.
Read()
Reads the next character from the input string and advances the character position by one character.
Read(Char[], Int32, Int32)
Reads a block of characters from the input string and advances the character position by count.
ReadAsync(Char[], Int32, Int32)
Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.
ReadBlock(Char[], Int32, Int32)
Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.
(Inherited from TextReader )
ReadBlockAsync(Char[], Int32, Int32)
Reads a specified maximum number of characters from the current string asynchronously and writes the data to a buffer, beginning at the specified index.
ReadLine()
Reads a line of characters from the current string and returns the data as a string.
ReadLineAsync()
Reads a line of characters asynchronously from the current string and returns the data as a string.
ReadToEnd()
Reads all characters from the current position to the end of the string and returns them as a single string.
ReadToEndAsync()
Reads all characters from the current position to the end of the string asynchronously and returns them as a single string.
ToString()
Returns a string that represents the current object.
(Inherited from Object )
Explicit Interface Implementations
Remarks
StringReader enables you to read a string synchronously or asynchronously. You can read a character at a time with the Read or the ReadAsync method, a line at a time using the ReadLine or the ReadLineAsync method and an entire
string using the ReadToEnd or the ReadToEndAsync method.
Note
This type implements the IDisposable interface, but does not actually have any resources to dispose. This means that disposing it by directly calling Dispose() or by using a language construct such as using (in C#) or Using (in Visual Basic) is not necessary.
The following table lists examples of other typical or related I/O tasks.
Applies to
.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1
See also
StreamWriter Class
Implements a TextWriter for writing information to a string. The information is stored in an underlying StringBuilder .
Namespace System.IO
Assemblies System.IO.dll, mscorlib.dll, netstandard.dll, System.Runtime.Extensions.dll
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class StreamWriter : System.IO.TextWriter
Inheritance: Object ->MarshalByRefObject ->TextWriter ->StreamWriter
Attributes: ComVisibleAttribute , SerializableAttribute
Constructors
Properties
Methods
Close()
Closes the current StringWriter and the underlying stream.
CreateObjRef(Type)
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject )
Dispose()
Releases all resources used by the TextWriter object.
(Inherited from TextWriter )
Dispose(Boolean)
Releases the unmanaged resources used by the StringWriter and optionally releases the managed resources.
Equals(Object)
Determines whether the specified object is equal to the current object.
(Inherited from Object )
Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
(Inherited from TextWriter )
FlushAsync()
Asynchronously clears all buffers for the current writer and causes any buffered data to be written to the underlying device.
GetHashCode()
Serves as the default hash function.
(Inherited from Object )
GetLifetimeService()
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject )
GetStringBuilder()
Returns the underlying StringBuilder .
GetType()
Gets the Type of the current instance.
(Inherited from Object )
InitializeLifetimeService()
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject )
MemberwiseClone()
Creates a shallow copy of the current Object .
(Inherited from Object )
MemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject )
ToString()
Returns a string containing the characters written to the current StringWriter so far.
Write(Boolean)
Writes the text representation of a Boolean value to the text stream.
(Inherited from TextWriter )
Write(Char)
Writes a character to the string.
Write(Char[])
Writes a character array to the text stream.
(Inherited from TextWriter )
Write(Char[], Int32, Int32)
Writes a subarray of characters to the string.
Write(Decimal)
Writes the text representation of a decimal value to the text stream.
(Inherited from TextWriter )
Write(Double)
Writes the text representation of an 8-byte floating-point value to the text stream.
(Inherited from TextWriter )
Write(Int32)
Writes the text representation of a 4-byte signed integer to the text stream.
(Inherited from TextWriter )
Write(Int64)
Writes the text representation of an 8-byte signed integer to the text stream.
(Inherited from TextWriter )
Write(Object)
Writes the text representation of an object to the text stream by calling the ToString method on that object.
(Inherited from TextWriter )
Write(Single)
Writes the text representation of a 4-byte floating-point value to the text stream.
(Inherited from TextWriter )
Write(String)
Writes a string to the current string.
Write(String, Object)
Writes a formatted string to the text stream, using the same semantics as the Format(String, Object) method.
(Inherited from TextWriter )
Write(String, Object, Object)
Writes a formatted string to the text stream using the same semantics as the Format(String, Object, Object) method.
(Inherited from TextWriter )
Write(String, Object, Object, Object)
Writes a formatted string to the text stream, using the same semantics as the Format(String, Object, Object, Object) method.
(Inherited from TextWriter )
Write(String, Object[])
Writes a formatted string to the text stream, using the same semantics as the Format(String, Object[]) method.
(Inherited from TextWriter )
Write(UInt32)
Writes the text representation of a 4-byte unsigned integer to the text stream.
(Inherited from TextWriter )
Write(UInt64)
Writes the text representation of an 8-byte unsigned integer to the text stream.
(Inherited from TextWriter )
WriteAsync(Char)
Writes a character to the string asynchronously.
WriteAsync(Char[])
Writes a character array to the text stream asynchronously.
(Inherited from TextWriter )
WriteAsync(Char[], Int32, Int32)
Writes a subarray of characters to the string asynchronously.
WriteAsync(String)
Writes a string to the current string asynchronously.
WriteLine()
Writes a line terminator to the text stream.
(Inherited from TextWriter )
WriteLine(Boolean)
Writes the text representation of a Boolean value to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Char)
Writes a character to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Char[])
Writes an array of characters to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Char[], Int32, Int32)
Writes a subarray of characters to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Decimal)
Writes the text representation of a decimal value to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Double)
Writes the text representation of a 8-byte floating-point value to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Int32)
Writes the text representation of a 4-byte signed integer to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Int64)
Writes the text representation of an 8-byte signed integer to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Object)
Writes the text representation of an object to the text stream, by calling the ToString method on that object, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(Single)
Writes the text representation of a 4-byte floating-point value to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(String)
Writes a string to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(String, Object)
Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object) method.
(Inherited from TextWriter )
WriteLine(String, Object, Object)
Writes a formatted string and a new line to the text stream, using the same semantics as the Format(String, Object, Object) method.
(Inherited from TextWriter )
WriteLine(String, Object, Object, Object)
Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object) .
(Inherited from TextWriter )
WriteLine(String, Object[])
Writes out a formatted string and a new line to the text stream, using the same semantics as Format(String, Object) .
(Inherited from TextWriter )
WriteLine(UInt32)
Writes the text representation of a 4-byte unsigned integer to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLine(UInt64)
Writes the text representation of an 8-byte unsigned integer to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLineAsync()
Asynchronously writes a line terminator to the text stream.
(Inherited from TextWriter )
WriteLineAsync(Char)
Asynchronously writes a character to the string, followed by a line terminator.
WriteLineAsync(Char[])
Asynchronously writes an array of characters to the text stream, followed by a line terminator.
(Inherited from TextWriter )
WriteLineAsync(Char[], Int32, Int32)
asynchronously writes a subarray of characters to the string, followed by a line terminator.
WriteLineAsync(String)
Asynchronously writes a string to the current string, followed by a line terminator.
Fields
Remarks
StringWriter enables you to write to a string synchronously or asynchronously. You can write a character at a time with the Write(Char) or the WriteAsync(Char) method, a string at a time using the Write(String) or the
WriteAsync(String) method. In addition, you can write a character, an array of characters or a string followed by the line terminator asynchronously with one of the WriteLineAsync methods.
Note
This type implements the IDisposable interface, but does not actually have any resources to dispose. This means that disposing it by directly calling Dispose() or by using a language construct such as using (in C#) or Using (in Visual Basic) is not necessary.
The following table lists examples of other typical or related I/O tasks.
Applies to
.NET Framework: 4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1
See also
Examples Examples of StringReader and StringWriter Classes
Vb.NET ASPX File: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server" >
Sub Page_Load()
Dim xstr As String
Dim xstr1 As String = "abcdefgh"
Dim xstr2 As String = "i"
Dim xpath As String = "T:\filestream\filestream.txt"
Dim xi As Integer
xstr = "Given string: " & xstr1 & "<br />"
xstr = xstr & "<br />instantiate a StringReader of given string:" & xstr1
Dim xstrreader As New System.IO.StringReader(xstr1)
xstr = xstr & "<br />instantiate a StringWriter" & "<br /><br />"
Dim xstrwriter As New System.IO.StringWriter()
xstr = xstr & "using stringreader to read string from original string.<br />"
xstr = xstr & "using stringwriter to write the modification of the original string."
For xi = 0 to xstr1.Length-1
xstrwriter.Write(xstrreader.Read() & xi)
Next
xstr = xstr & "<br />display the modified result: " & xstrwriter.ToString & "<br />"
lbl01.Text = xstr
End Sub
</script>
</head>
<body>
<%Response.Write("<p>Results on "& Request.ServerVariables("SERVER_SOFTWARE") & " .net: " & System.Environment.Version.ToString & " " & ScriptEngine & " Version " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "</p>")%>
<% Response.Write ("<h1>This is a Sample Page of StringReader and StringWriter Classes</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>
HTML Web Page Embedded Output:
Source/Reference
©sideway
ID: 200700013 Last Updated: 7/13/2020 Revision: 0 Ref:
References
Active Server Pages, , http://msdn.microsoft.com/en-us/library/aa286483.aspx
ASP Overview, , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
ASP Best Practices, , http://technet.microsoft.com/en-us/library/cc939157.aspx
ASP Built-in Objects, , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
Response Object, , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
Request Object, , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
Server Object (IIS), , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
Application Object (IIS), , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
Session Object (IIS), , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
ASPError Object, , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
ObjectContext Object (IIS), , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
Debugging Global.asa Files, , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
How to: Debug Global.asa files, , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
Calling COM Components from ASP Pages, , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
IIS ASP Scripting Reference, , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
ASP Keywords, , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
Creating Simple ASP Pages, , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
Including Files in ASP Applications, , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
ASP Overview, , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
FileSystemObject Object, , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx, , ADO Object Model
ADO Fundamentals, , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx