2 つの値の間に表示されるテキスト ファイルから文字列を取得する必要があります。たとえば、間の文字列を取得し、< postcode >W12 FGS < /postcode >
その文字列にスペースを配置する必要があるため、< postcode >W12 FGS < /postcode >
. このファイルには、100 を超える郵便番号を含めることができます。どうすればいいですか?
1222 次
1 に答える
0
とにかく、私が行くあなたの要求に基づいて、正規表現を扱うときは非常に正確である必要があります:
$pattern = [regex]::escape('< postcode >W12FGS < /postcode >')
$replaceWith = '< postcode >W12 FGS < /postcode >'
(Get-Content .\postcode.txt) |
Foreach-Object {$_ -replace $pattern,$replaceWith } |
Set-Content .\postcode.txt
コメントに基づいて更新し、フォルダー内の複数の xml の郵便番号を変更しました。
Get-ChildItem c:\postcodes -Filter *.xml | Foreach-Object{
[xml]$xml = Get-Content $_.FullName
$xml.SelectNodes('//c_postcode') | Foreach-Object{ $_.'#text' = $_.'#text'.Insert(3,' ') }
$xml.Save($_.FullName)
}
于 2012-08-13T14:19:57.490 に答える