码迷,mamicode.com
首页 > 系统相关 > 详细

Powershell替代和截断——replace and substring

时间:2017-07-10 14:35:49      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:span   nbsp   power   sub   截断   .sh   class   shell   特定   

一:截取一个字符串的尾部,替代字符串中的特定字符或替代字符串中特定位置的特定字符

$a="W.endy.chen.SHAO"

$b=$a.Substring(0,$a.Length-5) -replace "\.","_" 

$c=$a.Substring(0,$a.Length-5).Replace(".","_")

 
$d=($a.substring(0,$a.Length-5)) -replace "\.(?!.*\.)","_"

#只替换最后一个.为_,其他.保持不变

echo $a,$b,$c,$d

 
结果:

W.endy.chen.SHAO

W_endy_chen

W_endy_chen

W.endy_chen

 

 

Powershell替代和截断——replace and substring

标签:span   nbsp   power   sub   截断   .sh   class   shell   特定   

原文地址:http://www.cnblogs.com/thescentedpath/p/replaceandsubstring.html

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