Chapter 3: Pulling Strings
In This Chapter
Pulling and twisting a string with C# — just don’t string me along
Matching similar values
Doing other string operations, such as searching, trimming, splitting, and concatenating
Parsing strings read into the program
Formatting output strings manually or using the String.Format()
method
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 (I cover classes in Book II):
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 ...