O'Reilly logo

Professional C# 6 and .NET Core 1.0 by Christian Nagel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10 Strings and Regular Expressions

What’s In This Chapter?

  • Building strings
  • Formatting expressions
  • Using regular expressions

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/professionalcsharp6 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • StringSample
  • StringFormats
  • RegularExpressionPlayground

Strings have been used consistently since the beginning of this book, as every program needs strings. However, you might not have realized that the stated mapping that the string keyword in C# actually refers to is the System.String .NET base class. String is a very powerful and versatile class, but it is by no means the only string-related class in the .NET armory. This chapter begins by reviewing the features ofString and then looks at some nifty things you can do with strings using some of the other .NET classes—in particular those in the System.Text and System.Text.RegularExpressions namespaces. This chapter covers the following areas:

  • Building strings—If you’re performing repeated modifications on a string—for example, to build a lengthy string prior to displaying it or passing it to some other method or application—the String class can be very inefficient. When you find yourself in this kind of situation, another class, System.Text.StringBuilder, is more suitable because it has been designed exactly for this scenario.
  • Formatting expressions—This chapter takes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required