问题
Is there an easy way to replace special characters, like æøåéü etc., from a string in a Powershell script?
Making the string web-safe.
回答1:
Ok, with additional explanation, I guess solution would depend on a scale. If that's user input and in "normal" use it would be short, that maybe something like that:
$Replacer = @{
Å = 'aa'
é = 'e'
}
$string_to_fix = 'æøåéüÅ'
$pattern = "[$(-join $Replacer.Keys)]"
[regex]::Replace($string_to_fix, $pattern, { $Replacer[$args[0].value] })
Obviously, you would have to fill in the blanks for $Replacer ;) HTH Bartek
来源:https://stackoverflow.com/questions/10829919/powershell-replace-special-characters