Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Splitting pairs of charavters in Powershell, odd results

$
0
0

I am writing a script to take a list of characters for replacement and the replacement text for filename replacement. This will be for file name compatibility with skydrive pro.

I am falling over checking that the character pairs are coming out correctly. I have:

$characters = @'
&,and
..,.
:,-
<,-
>,-
|,-
#,-
{,-
},-
%,-
~,-
'@

foreach($character in $characters)
{
    
    
    $old = $character.split(',')[0]
    $new = $character.split(',')[1]
    
    #Write-Host "both: $character`nold: $old`nnew: $new"
    Write-Host "both: $character"
    Write-Host "old: $old"
    Write-Host "new: $new"
    
}

I would expect the output to be:

both: &,and
old: &
new: and
both: ..,.
old: ..
new: .
both: :,-
old: :
new: -

and so on

Instead I am seeing

both: &,and
..,.
:,-
<,-
>,-
|,-
#,-
{,-
},-
%,-
~,-
old: &
new: and
..

I get the same results with the single line write-host that uses `n

It gives me no confidence that file name replacement will work. Am I missing something in the characters used in the string that makes it go wonkey?


Viewing all articles
Browse latest Browse all 15370

Trending Articles



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