字符串&数组的相互转换

时间:2015-05-10 22:04:59   收藏:0   阅读:109
字符串 -> 数组

方法一:

$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
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!