gpt4 book ai didi

powershell - 用字符串中的变音符号替换字符

转载 作者:行者123 更新时间:2023-12-02 22:17:22 24 4
gpt4 key购买 nike

我试图摆脱一些特殊字符。

在这种情况下,瑞典语 ÅÄÖ 和 åäö。为什么这不起作用?

结果应该是 AAOaao但我得到 ÅÄÖåäO ?

$stringX = "ÅÄÖåäö"

$stringX = ($stringX -replace "Å$","A")
$stringX = ($stringX -replace "Ä$","A")
$stringX = ($stringX -replace "Ö$","O")
$stringX = ($stringX -replace "å$","a")
$stringX = ($stringX -replace "ä$","a")
$stringX = ($stringX -replace "ö$","o")

"Result = $stringX"

最佳答案

尝试这个 :

function RemoveDiacritics([System.String] $text)
{

if ([System.String]::IsNullOrEmpty($text))
{
return text;
}


$Normalized = $text.Normalize([System.Text.NormalizationForm]::FormD)
$NewString = New-Object -TypeName System.Text.StringBuilder

$normalized.ToCharArray() | ForEach{
if ([Globalization.CharUnicodeInfo]::GetUnicodeCategory($psitem) -ne [Globalization.UnicodeCategory]::NonSpacingMark)
{
[void]$NewString.Append($psitem)
}
}

return $NewString.ToString()



}

RemoveDiacritics "îïùûüöôâàäéèêëÿç"

RemoveDiacritics "ÅÄÖåäö"

关于powershell - 用字符串中的变音符号替换字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43493484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com