The .NET Framework provides two basic classes for manipulating text: the String and String-Builder classes.
The String class exposes a large number of practical methods, and they’re all reference methods: They don’t act on the string directly but return another string instead. After you assign a value to a String object, that’s it. You can examine the string, locate words in it, and parse it, but you can’t edit it. The String class exposes methods such as the Replace and Remove methods, which replace a section of the string with another and remove a range of characters from the string, respectively. These methods, however, don’t act on the string directly: They replace or remove parts of the original string and then return the result as a new string.
The StringBuilder class is similar to the String class: It stores strings, but it can manipulate them in place. In other words, the methods of the StringBuilder class are instance methods.
The distinction between the two classes is that the String class is better suited for static strings, whereas the StringBuilder class is better suited for dynamic strings. Use the String class for strings that don’t change frequently in the course of an application, and use the StringBuilder class for strings that grow and shrink dynamically. The two classes expose similar methods, but the String class’s methods return new strings; if you need to manipulate large strings extensively, using the String class might fill the memory quite quickly.
Any code that manipulates strings must also be able to manipulate individual characters. The Framework supports the Char class, which not only stores characters but also exposes numerous methods for handling them. Both the String and StringBuilder classes provide methods for storing strings into arrays of characters, as well as for converting character arrays into strings. After extracting the individual characters from a string, you can process them with the members of the Char class. We’ll start our discussion of the text-handling features of the Framework with an overview of the Char data type, and we’ll continue with the other two major components, the String and StringBuilder classes.