Chapter 3
Pulling Strings
IN THIS CHAPTER
Pulling and twisting a string with C#
Matching searching, trimming, splitting, and concatenating strings
Parsing strings read into the program
Formatting output strings manually or using String.Format()
For many applications, you can treat a string like one of the built-in value-type variable types such as int or char. Certain operations that are otherwise reserved for these intrinsic types are available to strings:
int i = 1; // Declare and initialize an int.string s = "abc"; // Declare and initialize a string.
In other respects, as shown in the following example, a string is treated like a user-defined class (Book 2 discusses classes):
string s1 = new String();string s2 = "abcd";int lengthOfString = s2.Length;
Which is it — a value type or a class? In fact, String is a class for which C# offers special treatment because strings are so widely used in programs. The keyword string is an alias of the String class, as shown in this bit of code:
String s1 = "abcd"; // Assign a string literal to a String obj.string s2 = s1; // Assign a String ...