如何插入软连字符

Luk*_*101 1 c# powershell powershell-2.0

我想使用powershell在单词中的每个字母之间插入一个软连字符.例如,这里有一些文字:

Thisisatest => T-h-i-s-i-s-a-t-e-s-t
Run Code Online (Sandbox Code Playgroud)

-是一个柔软的连字符.我怎么能在powershell中这样做?

Ada*_*cin 6

使用.NET方法比规范的PowerShell代码更多,您可以编写

$word = "Thisisatest"
[System.String]::Join("-", $word.ToCharArray())
Run Code Online (Sandbox Code Playgroud)

和Powershell输出"Thisisatest"

编辑:对于一个真正的软连字符,并在PowerShell中使用Unicode的这个答案,我会将第二行更改为

[System.String]::Join([char] 0x00AD, $word.ToCharArray())
Run Code Online (Sandbox Code Playgroud)


Tre*_*van 6

您可以使用PowerShell友好的-join运算符来执行此操作:

"Thisisatest".ToCharArray() -join '-'
Run Code Online (Sandbox Code Playgroud)

有关-join PowerShell运算符的更多信息,请查看PowerShell Technet帮助.

http://technet.microsoft.com/en-us/library/dd315375.aspx