Powershell: Replace special characters

扶醉桌前 提交于 2019-12-24 11:46:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!