Press "Enter" to skip to content

Building Strings in Powershell with StringBuilder

Robert Cain takes to a .NET class to build some strings:

As I was creating the next post in my ArcaneBooks series, I realized I had not written about the StringBuilder class. As the code in my ArcaneBooks module relies on it in several places, I thought it best to add a new post to my Fun With PowerShell series explaining how to use it before continuing.

It’s a common need in any language, and PowerShell is no exception, to need to add more text to an existing string.

Read on to understand why the StringBuilder class exists and how to use it. If you’re doing a lot of string manipulation, particularly of large strings in loops, this can provide a noticeable performance impact.