Cover by Morgan Skinner, Karli Watson, Jay Glynn, Bill Evjen, 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

O'Reilly logo

Chapter 9

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 http://www.wrox.com/remtitle.cgi?isbn=1118314425 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • Encoder.cs
  • Encoder2.cs
  • FormattableVector.cs
  • RegularExpressionPlayground.cs
  • StringEncoder.cs

Strings have been used consistently since the beginning of this book, but 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. System.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 of System.String 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.

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