Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Replace does not work

$
0
0

Hi,

I need to replace all characters between 1 and 31 (ASCII) for space in a file.

I created a script to test but it is not working (I tried two alternatives to replace).

$a = "Test$([char]26)Test$([char]27)Test"

$File_out = Join-Path $PSScriptRoot "teste.txt"

Remove-Item $File_out -ErrorAction SilentlyContinue

Add-Content -Path $File_out -Value $a

for($codAscii=1;$codAscii -le 31;$codAscii++){
    $codAscii
    $b = $a.Replace([char]$codAscii," ")
    $c = $a -replace [char]$codAscii," "
}

Add-Content -Path $File_out -Value $b
Add-Content -Path $File_out -Value $c

Result:

What I need

Thanks in advance.


Fábio de Paula Junior



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>