How do I create a string with repeating characters?

Is there a function to create a string with repeated characters in Powershell? I am looking for something like,

$string = repeat-char("*",35)

Thanks.

November 11th, 2010 9:56pm

$str = "*" * 35

:)

Free Windows Admin Tool Kit Click here and download it now
November 11th, 2010 10:03pm

Great!  Thanks Sam.

November 12th, 2010 12:59am

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)    
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2010 3:05am

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

August 8th, 2015 8:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics