字符串 -> 数组
方法一:
$str = "abcd"
$s2 = $str.GetEnumerator() #$s2是无法使用下标的方式进行索引的,因为其不是array
$s2 | % {$_ + "y8y"}
$str = "abcd"
Foreach ($s in $str.GetEnumerator()) {$s + "y8y"}
方法二:
$str = "abcd"
$str.tochararray()
输出结果:
ay8y
by8y
cy8y
dy8y
数组 -> 字符串
方法一:
$info = ‘One‘, ‘Two‘, ‘Three‘
$info | Out-String
方法二:
$info = Get-Content $env:windir\windowsupdate.log -Raw
参考:
http://blog.vichamp.com/powershell/tip/2014/05/19/converting-text-arrays-to-string
http://www.cnblogs.com/dreamer-fish/p/3942023.html
时间: 2024-08-27 15:05:39