如何在 PowerShell 中删除重音符号? [英] How remove accents in PowerShell?

查看:29
本文介绍了如何在 PowerShell 中删除重音符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Microsoft Exchange Server 和 Active Directory 中创建用户的脚本.因此,尽管在西班牙用户名带有重音或 - 是很常见的,但我想避免使用它们,因为用户名不会导致旧系统中的任何不兼容.

I have a script which creates users in Microsoft Exchange Server and Active Directory. So, though it's commmon that user's names have accents or ñ in Spain, I want to avoid them for the username to not to cause any incompatibilities in old systems.

那么,我如何清理这样的字符串?

So, how could I clean a string like this?

$name = "Ramón"

变成那样?:

$name = "Ramon"

推荐答案

好吧,我可以帮你处理一些代码......

Well I can help you with some of the code.....

我最近在一个 c# 项目中使用它来去除电子邮件地址:

I used this recently in a c# project to strip from email addresses:

    static string RemoveDiacritics(string input)
    {
        string inputFormD = (input ?? string.Empty).Normalize(NormalizationForm.FormD);
        StringBuilder sb = new StringBuilder();

        for (var i = 0; i < inputFormD.Length; i++)
        {
            UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(inputFormD[i]);
            if (uc != UnicodeCategory.NonSpacingMark)
            {
                sb.Append(inputFormD[i]);
            }
        }

        return (sb.ToString().Normalize(NormalizationForm.FormC));
    }

我想我现在可以说'扩展到 PowerShell 脚本/表单是留给读者'....希望它有帮助....

I guess I can now say 'extending into a PowerShell script/form is left to the reader'.... hope it helps....

这篇关于如何在 PowerShell 中删除重音符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆