Strings, the String Class, and the StringBuilder Class

Michael McMillan · Cambridge University Press eBooks · 2005

Strings are common to most computer programs. Certain types of programs, such as word processors and Web applications, make heavy use of strings, which forces the programmer of such applications to pay special attention to the efficiency of string processing. In this chapter we examine how VB.NET works with strings, how to use the String class, and how to work with the StringBuilder class. The StringBuilder class is used when a program must make many changes to a String object because strings and String objects are immutable, whereas StringBuilder objects are mutable. We'll explain all this later in the chapter. WORKING WITH THE STRING CLASS A string is a series of characters that can include letters, numbers, and other symbols. String literals are created in VB.NET by enclosing a series of characters within a set of double quotation marks. Here are some examples of string literals: “David Ruff” “the quick brown fox jumped over the lazy dog” “123-45-6789” “[email protected]” A string can consist of any character that is part of the Unicode character set. A string can also consist of no characters. This special string, called the empty string , is shown by placing two double quotation marks next to each other (“”). Keep in mind that this is not the string that represents a space. That string looks like this: “ ”. Strings in VB.NET have a schizophrenic nature: They are both native types and objects of a class.

Read the paper · More papers on PaperTik