Background
A few weeks ago, I was in a jam.
I wanted to draw a line on my console to separate out two sections of output.
It seems terrible inefficient to use Write-Output(“—————————————-“).
I preferred something like Write-Output(repeatChars(‘-‘, 80)).
Code
Here is stolen code that I have to come back and properly attribute ( give credit ).
function repeatChars([char] $ch, [int] $length) { [string] $data = ""; <# Initiate new Object Object Type:- String Argument List:- a) Char ( $ch ) b) Number of characters ( $length) #> $data = New-Object -TypeName String -Argument List $ch, $length; return ( $data ); }
Basis
Microsoft
.Net
Learn > .NET > API browser > System > String > String Constructors
Overloaded constructor syntax
Repeat Char (c), N Times
String(Char c, Int32 count) Initializes the new instance to the value indicated by a specified Unicode character repeated a specified number of times.
References
- Microsoft
- .Net
- Learn > .NET > API browser > System > String
- String Constructors
Link
- String Constructors
- Learn > .NET > API browser > System > String
- .Net