PoshCode Archive  Artifact [dbc902c81a]

Artifact dbc902c81abb4ca398f57b9e539861b54099c9bd6c18d3b0de5d7421794f6c5c:

  • File Remove-diacritics.ps1 — part of check-in [a77acd02d3] at 2018-06-10 12:56:20 on branch trunk — Remove diacritics from string : (user: Grgory Schiro size: 1022)

# encoding: utf-8
# api: powershell
# title: Remove diacritics
# description: Remove diacritics from string :
# version: 0.1
# type: function
# author: Grgory Schiro
# license: CC0
# function: Remove-Diacritics
# x-poshcode-id: 1054
# x-archived: 2017-05-13T16:17:56
# x-published: 2009-04-23T05:52:00
#
# PS> Remove-Diacritics -String ‘éàçèöîïñùà’
# eaceoiinua
#
### Grégory Schiro, 2009

### <summary>
### Removes diacritics from string.
### </summary>
### <param name="String">String containing diacritics</param>
function Remove-Diacritics([string]$String)
{
    $objD = $String.Normalize([Text.NormalizationForm]::FormD)
    $sb = New-Object Text.StringBuilder

    for ($i = 0; $i -lt $objD.Length; $i++) {
        $c = [Globalization.CharUnicodeInfo]::GetUnicodeCategory($objD[$i])
        if($c -ne [Globalization.UnicodeCategory]::NonSpacingMark) {
          [void]$sb.Append($objD[$i])
        }
      }

    return("$sb".Normalize([Text.NormalizationForm]::FormC))
}