Storing and manipulating text

The most common type of data for variables is text. The most common types in .NET for working with text are show in the following table:

Namespace

Type

System

Char

System

String

System.Text

StringBuilder

System.Text.RegularExpressions

Regex

Getting the length of a string

Add a new console application project named Ch04_ManipulatingText.

In Visual Studio 2017, set the solution's startup project to be the current selection.

Sometimes, you need to find out the length of a piece of text stored in a string class. Modify the code to look like this:

    using static System.Console; 
 
    namespace Ch04_ManipulatingText 
    { 
      class Program 
      { 
        static void Main(string[] args) 
        { 
          string city = "London"; WriteLine($"{city} ...

Get C# 7 and .NET Core now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.