PoshCode Archive  Artifact Content

Artifact 4f422a30ee256e9b240d4fa5b36f12ec50903a5ff6d769a58d978ef3094a4816:

  • File Remove-diacritics.ps1 — part of check-in [0cf1a21594] at 2018-06-10 13:24:00 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: 3330
# x-archived: 2017-05-17T23:55:28
# x-published: 2012-04-10T02:49: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))
}