I would like to insert a soft hyphen between every letter in a word using powershell. for example here is some text:
Thisisatest => T-h-i-s-i-s-a-t-e-s-t
-
is a soft hyphen. How might i do this in powershell?
I would like to insert a soft hyphen between every letter in a word using powershell. for example here is some text:
Thisisatest => T-h-i-s-i-s-a-t-e-s-t
-
is a soft hyphen. How might i do this in powershell?
Using .NET methods a little more than canonical PowerShell code, you can write
$word = "Thisisatest"
[System.String]::Join("-", $word.ToCharArray())
and Powershell outputs "T-h-i-s-i-s-a-t-e-s-t"
EDIT: For a true soft hyphen, and using this answer on Unicode in PowerShell, I would change the second line to
[System.String]::Join([char] 0x00AD, $word.ToCharArray())
You can use the PowerShell-friendly -join operator to do this:
"Thisisatest".ToCharArray() -join '-'
Look at the PowerShell Technet help for more information about the -join PowerShell operator.
My Prof. PowerShell column on the topic of splitting and joining: http://mcpmag.com/articles/2011/10/18/split-and-join-operators.aspx
Personally, I think you should avoid using .NET classes and methods unless there is no "native" PowerShell cmdlet or operator.