Introduction

The string type is one of the most used types in the C# framework. Two strings are either exactly equal, or are equal according to some pattern. Regular expressions flexibly define whether two strings are equal according to some pattern. Regular expressions offer a wide variety of pattern matching operators so that equality assertions can act flexibly.

Types of string assertions

Assertions on strings are performed using either the classical or constraint model. In this lesson, we’ll present the constraint model of string assertion, given that it is more flexible. In this context, string assertions are categorized into five groups:

  • The Empty string constraints
  • The EndWith constraints
  • The StartWith constraints
  • The substring constraints
  • The regex constraints

The string assertion categories are summarized below.

The Empty string constraint

These are used to check whether or not a string is empty. Its syntax is as follows:

Get hands-on with 1200+ tech skills courses.