C# String WriterTutorial with Programming Examples and Codes

StringWriter
In this chapter you will learn:

  • What is StringWriter class in C#?
  • How to write text in a file using StringWriter class
  • Programming Examples and Codes

What is StringWriter class?

StringWriter class is derived from TextWriter class and it is mainly used to manipulate string rather than files. StringWriter enables you to write to a string synchronously or asynchronously. You can write a character with Write(Char) or WriteAsync(Char) method and writer string with Write(String) or WriterAsync(String) method. The text or information written by StringWriter class is stored inside a StringBuilder.

Note: StringWriter is not for writing files on local disk. It is used for manipulate string and it saves information in StringBuilder.




  • How to write text in a file using StringWriter class?

    Explanation

    This example demonstrate well StringWriter() and StringReader() Class. String variable text stores a string value and using StringWriter this string value gets stored in StringBuilder. Next using StringReader the data gets displayed on console.

    Summary

    In this chapter you have learned StringWriter in details with complete programming examples and codes. The next chapter explains StringReader.


    Leave a Reply

    Your email address will not be published. Required fields are marked *