Is there a function to create a string with repeated characters in Powershell? I am looking for something like,
$string = repeat-char("*",35)
Thanks.
Technology Tips and News
Is there a function to create a string with repeated characters in Powershell? I am looking for something like,
$string = repeat-char("*",35)
Thanks.
$str = "*" * 35
:)
Great! Thanks Sam.
It is interesting to compare these uses of "*" * 35 PS C:> "*" * 35 *********************************** PS C:> 35 * "*" The '*' operator failed: Cannot convert value "*" to type "System.Int32". ... (string's * operator is not commutative) PS C:> write-output "*" * 35 * * 35 PS C:> write-output ("*" * 35) *********************************** (using Write-Output is tricky)For someone coming across this later.
Because asterisk is a special character in Powershell, you must use the escape character before it if you want it to be interpreted literally by Powershell:
"`*&qu