PoshCode Archive  Artifact [d1377c532b]

Artifact d1377c532b2baf22e2eba3a956d7ba71814f57b68c875ee89da3d68514f0ede1:

  • File Repair-ScriptQuotes.ps1 — part of check-in [8320dbe74c] at 2018-06-10 13:31:34 on branch trunk — Script to replace special quote characters when copy – pasting from Word or from blogs. (user: P Sczepanski size: 1621)

# encoding: ascii
# api: powershell
# title: Repair-ScriptQuotes
# description: Script to replace special quote characters when copy – pasting from Word or from blogs.
# version: 0.1
# type: function
# author: P Sczepanski
# license: CC0
# function: Repair-ScriptQuotes
# x-poshcode-id: 3816
# x-archived: 2012-12-16T04:25:52
# x-published: 2012-12-11T13:16:00
#
# See also my blog entry “Quote or not quote” at http://redtoo.com/blog/?cat=13
#
function Repair-ScriptQuotes {
    param (
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [string]$path
    )
    if ( !( Test-Path $path ) ) {
        Write-Warning "'$path' does not exist."
        Continue
    }
        

    (( Get-Content $path) |  
        ForEach-Object {
            # replace double quotes
            [Net.WebUtility]::HtmlDecode($_)
        } | 
            ForEach-Object {
                # replace double quotes
                $_ -replace "(\u201c|\u201d|\u201e)",[char]34
            } | 
                ForEach-Object {
                    # replace single quotes
                    $_ -replace "(\u2018|\u2019|\u201a)",[char]39
                } | 
                    ForEach-Object {
                        # replace dash
                        $_ -replace "(\u2013)",[char]45
                    } | 
                        ForEach-Object {
                            # replace tab with four spaces
                            $_ -replace "`t",(" " * 4)
                        }) | 
                            Set-Content $path
    Write-Host "Done"
}