Working with Strings in .NET
Introduction So, by now you should know all there is to about string concatenation in .NET and the StringBuilder class and the string.Concat method. I'm not going to cover that here, but, instead, some less known functionality around strings that can (also) bring some performance advantages. Searching When it comes to searching for values ("needles") inside a string ("haystack"), we have a couple options: Using the built-in string methods, such as string.IndexOf , string.IndexOfAny , string.Contains The ContainsAny extension that works with memory spans Using regular expressions with Regex , for more advanced pattern matching Since .NET 8, we have another one: the SearchValues<T> class. This one is optimised for searching for one or multiple strings (exact values) inside of a string. During its creation, it parses the string and builds a memory model that is suitable for searching. With time, using SearchValues<T...