我有一个字符串,我想剪切一些字符并将其存储到新文件中。
我尝试了此代码,但仍然出错。
BigDecimal
答案 0 :(得分:2)
尝试这样的事情:
$a = ";Code=NB"
$null, $b, $null = $a -split '=', 3
$b
$Save = "[AGM]", "CR=JP", "LOC= $b"| Out-File "C:\Users\Out.txt"
答案 1 :(得分:1)
更容易维护的是这样的:
#Words to remove from string
$wordsToCut = "This","is"
#Phrase to remove words from
$phrase = "This is a test"
#Running through all words in words to remove
foreach ($word in $wordsToCut){
#Replace current word with nothing
$phrase = $phrase.Replace($word,"")
}
#Output end result
Write-Host $phrase
您还可以使用修剪删除任何前导或尾随空格。上面的代码输出:
测试