Chapter 5. C Text Manipulation and File IO

 < Day Day Up > 

Chapter 5. C# Text Manipulation and File I/O

Topics in This Chapter

  • Characters and Unicode: By default, .NET stores a character as a 16-bit Unicode character. This enables an application to support international character sets a technique referred to as localization.

  • String Overview: In .NET, strings are immutable. To use strings efficiently, it is necessary to understand what this means and how immutability affects string operations.

  • String Operations: In addition to basic string operations, .NET supports advanced formatting techniques for numbers and dates.

  • StringBuilder: The StringBuilder class offers an efficient alternative to concatenation for constructing screens.

  • Regular Expressions: The .NET Regex class provides an engine that uses regular expressions to parse, match, and extract values in a string.

  • Text Streams: Stream classes permit data to be read and written as a stream of bytes that can be encrypted and buffered.

  • Text Reading and Writing: The StreamReader and StreamWriter classes make it easy to read from and write to physical files.

  • System.IO: Classes in this namespace enable an application to work with underlying directory structure of the host operating system.

This chapter introduces the string handling capabilities provided by the .NET classes. Topics include how to use the basic String methods for extracting and manipulating string content; the use of the String.Format method to display numbers and dates in special formats; and the use of regular expressions (regexes) to perform advanced pattern matching. Also included is a look at the underlying features of .NET that influence how an application works with text. Topics include how the Just-In-Time (JIT) compiler optimizes the use of literal strings; the importance of Unicode as the cornerstone of character and string representations in .NET; and the built-in localization features that permit applications to automatically take into account the culture-specific characteristics of languages and countries.

This chapter is divided into two major topics. The first topic focuses on how to create, represent, and manipulate strings using the System.Char, System.String, and Regex classes; the second takes up a related topic of how to store and retrieve string data. It begins by looking at the Stream class and how to use it to process raw bytes of data as streams that can be stored in files or transmitted across a network. The discussion then moves to using the Textreader/TextWriter classes to read and write strings as lines of text. The chapter concludes with examples of how members of the System.IO namespace are used to access the Microsoft Windows directory and file structure.

     < Day Day Up > 

    Core C# and  .NET
    Core C# and .NET
    ISBN: 131472275
    EAN: N/A
    Year: 2005
    Pages: 219 © 2008-2017.
    If you may any questions please contact us: