Multiplying Strings in PowerShell
One feature of PowerShell has always baffled me; why would anyone ever want to multiply a string? Of course Scripting Guy Ed Wilson had a use case for it.
One of the really cool things that I use the string multiplication trick to do is to create an underline that is exactly the same length as the string it highlights. To do this, I use the Length property of the string and supply that to the multiplication operator along with the desired line separator to use. In the code that follows, I assign a string to the variable $a. Next, I use the Length property, which is a property that always exists on System.String objects, to determine the length of the string. I use the length of the string to determine how many times I want to multiply the underscore character (“_”). Next I display the string, and finally, I display the newly created underline. The code is shown here.
3 months ago - link

