Warm tip: This article is reproduced from stackoverflow.com, please click
powershell

How to add a space (' ') after the 10th character in a string in PowerShell?

发布于 2020-04-03 23:19:45

Hey PowerShell noobie here.

Please can somebody point me in the right direction on how to add a space ' ' after then 10th character in the string below:

$var = '01/03/202012:00:00'

The finished result should look like this:

$var = '01/03/2020 12:00:00'

Thanks a heap!

Questioner
BennKingy
Viewed
26
186k 2020-01-31 03:26

Try this...

$var = '01/03/202012:00:00'.insert(10, ' ')

enter image description here

And, for future reference, you can see the list of string functions with something like... (gm is the built-in alias for the Get-Member cmdlet)

enter image description here