Sideway
output.to from Sideway
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.

NamespaceSystem.IO AssembliesSystem.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

StringReader(String)

Initializes a new instance of the StringReader class that reads from the specified string.

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

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.

NamespaceSystem.IO AssembliesSystem.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

StringWriter()

Initializes a new instance of the StringWriter class.

StringWriter(IFormatProvider)

Initializes a new instance of the StringWriter class with the specified format control.

StringWriter(StringBuilder)

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder.

StringWriter(StringBuilder, IFormatProvider)

Initializes a new instance of the StringWriter class that writes to the specified StringBuilder and has the specified format provider.

Properties

Encoding

Gets the Encoding in which the output is written.

FormatProvider

Gets an object that controls formatting.

(Inherited from TextWriter)
NewLine

Gets or sets the line terminator string used by the current TextWriter.

(Inherited from TextWriter)

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

CoreNewLine

Stores the newline characters used for this TextWriter.

(Inherited from TextWriter)

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.

To do this... See the example in this topic...
Create a text file. How to: Write Text to a File
Write to a text file. How to: Write Text to a File
Read from a text file. How to: Read Text from a File
Append text to a file. How to: Open and Append to a Log File

File.AppendText

FileInfo.AppendText
Get the size of a file. FileInfo.Length
Get the attributes of a file. File.GetAttributes
Set the attributes of a file. File.SetAttributes
Determine if a file exists. File.Exists
Read from a binary file. How to: Read and Write to a Newly Created Data File
Write to a binary file. How to: Read and Write to a Newly Created Data File

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:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019