How can i turn Turkish chars to ascii? (like ş to s) i tried replace but it didn't do anything. Here some piece of my code:
$posta = $posta.ToLower()
$posta = $posta -replace "ü","u"
$posta = $posta -replace "ı","i"
$posta = $posta -replace "ö","o"
$posta = $posta -replace "ç","c"
$posta = $posta -replace "ş","s"
$posta = $posta -replace "ğ","g"
$posta = $posta.trim()
write-host $posta
if $posta was eylül it returns eylül
CodePudding user response:
All credits to this answer combined with the comment in the same answer which shows the appropriate way to do it by filtering for characters which are not NonSpacingMark
followed by replacing ı
with i
. The answer is in c# hence sharing how it can be done in powershell.
$posta = 'üıöçşğ'
$posta = [string]::Join('',
$posta.Normalize([Text.NormalizationForm]::FormD).ToCharArray().
Where{ [char]::GetUnicodeCategory($_) -ne [Globalization.UnicodeCategory]::NonSpacingMark }
).Replace("ı", "i")