2015-12-07 44 views
1

我想截斷一個字符串,我從Excel文件中獲取。Powershell截斷字符串

的字符串(URL)是:;#://abc.com/sites/abcx/000000103483/default.aspx;#000000103483;#

我需要它是:abc.com /網站/ ABCX/000000103483/

但問題是ABCX在URL範圍從ABCXabcxxxx,其中x是一個整數。

我如何獲得所需的結果?

回答

1

在PowerShell中,你可能分裂的/ S和建立你想要像這樣的字符串:

$string = ";#://abc.com/sites/abcx/000000103483/default.aspx;#000000103483;#" 
$split = $string.Split("/") 
$split[2] + "/" + $split[3] + "/" + $split[4] + "/" + $split[5] + "/" 

輸出:

abc.com/sites/abcx/000000103483/ 
1

刪除default.aspx和隨之而來它背後的一切。

$s = ';#://abc.com/sites/abcx/000000103483/default.aspx;#000000103483;#' 
$s -replace 'default\.aspx.*' 
+0

非常感謝..這有助於.. – kaz