C# – Use StringAssert when testing a string for substrings

When you’re testing if two strings are equal, you can simply use Assert.AreEqual(). When you’re testing if a string contains a substring or a pattern, typically developers use Assert.IsTrue() with a substring method or regex. You should use StringAssert instead, because it gives better failure messages. The key problem is Assert.IsTrue() gives useless information. You … Read more C# – Use StringAssert when testing a string for substrings

Regex in .NET: Using named capturing groups to extract data

In regex, capturing groups give you a way to save text and refer to it later. Capturing groups can be named, and referred to by their name. When they aren’t named, you refer to them by their index number. In this article, I’ll show how to use named capturing groups by solving the problem of … Read more Regex in .NET: Using named capturing groups to extract data