分离拥挤的单词

Posted on 2019-03-22 17:10  努力成长静待花开  阅读(122)  评论(0编辑  收藏  举报

实现效果:
  

实现代码:

filter Split-UpperChars
{
   param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$str)
   $offset=0;$s=$str
   1..$str.length|%{
   if($str[$_] -cmatch "[A-Z]"){
   $s=$s.Insert(($_+$offset),' ')
   $offset+=1}};return $s
}

>2

"Address Bar" -creplace "[A-Z]"," `$0"

>3

regex]::Replace("AddressBar","[A-Z]",{param($x) " "+$x.value})