Working with text
One of the other most common types of data for variables is text. The most common types in .NET for working with text are shown in Table 8.2:
Namespace | Type | Description |
System |
Char |
Storage for a single text character |
System |
String |
Storage for multiple text characters |
System.Text |
StringBuilder |
Efficiently manipulates strings |
System.Text.RegularExpressions |
Regex |
Efficiently pattern-matches strings |
Getting the length of a string
Let's explore some common tasks when working with text; for example, sometimes you need to find out the length of a piece of text stored in a string
variable:
- Use your preferred code editor to add a new Console App /
console
project namedWorkingWithText
to theChapter08
solution. - In the
WorkingWithText
project, inProgram.cs
, delete the existing statements and then add statements to define a variable to store the name of the city, London, and then write its name and length...