This is a general newb question. Love powershell, but I definitely don't get something here:
I am creating a simple function to replicate a string x times. I have some kind of weird problem with a parameter - it doesn't seem to recognize the second parameter.
When I run the function, it returns an empty string. Also, I think it combines 2 parameters into 1. Here is my code:
Function Repeat-String([string]$str, [int]$repeat) {
$builder = new-object System.Text.StringBuilder
for ($i = 0; $i -lt $repeat; $i++) {[void]$builder.Append($str)}
$builder.ToString()
}
first I am a point source to load it:
. .\RepeatString.ps1
then I will do it like this:
Repeat-string("x", 7)
I was expecting a string of 7 x. I got an empty string.
, "for". "-lt $repeat" "-lt 5", . , ( ):
Repeat-String ( "x", 7)
"x 7x 7x 7x 7x 7"
, $str $repeat , 2 . , ?