码迷,mamicode.com
首页 > 编程语言 > 详细

字符串&数组的相互转换

时间:2015-05-10 22:04:59      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

字符串 -> 数组

方法一:

$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

字符串&数组的相互转换

标签:

原文地址:http://www.cnblogs.com/IvanChen/p/4493028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!