如何在PowerShell中删除的口音? [英] How remove accents in PowerShell?

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

问题描述

我有造成用户在Microsoft Exchange Server和Active Directory的脚本。所以,虽然它commmon该用户名在西班牙口音或N,我想避免他们的用户名,以不造成任何不兼容的旧系统。

所以,我怎么可以清理一个字符串这样吗?

  $ NAME =拉蒙
 

要这样呢?

  $ NAME =拉蒙
 

解决方案

嗯,我可以帮你与一些code .....

我在C#项目中使用这个最近从电子邮件地址剥离:

 静态字符串RemoveDiacritics(字符串STIN)
    {
        字符串stFormD =(STIN ??的S​​tring.Empty).Normalize(NormalizationForm.FormD);
        StringBuilder的SB =新的StringBuilder();

        对于(INT ICH = 0; ICH< stFormD.Length; ICH ++)
        {
            统一codeCategory UC = CharUni codeInfo.GetUni codeCategory(stFormD [ICH]);
            如果(UC!=统一codeCategory.NonSpacingMark)
            {
                sb.Append(stFormD [ICH]);
            }
        }

        返程(sb.ToString()标准化(NormalizationForm.FormC)。);
    }
 

我想我现在可以说'延伸到PowerShell脚本/形式留给读者......希望它可以帮助...

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"

To be like that? :

$name = "Ramon"

解决方案

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

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

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

        for (int ich = 0; ich < stFormD.Length; ich++)
        {
            UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
            if (uc != UnicodeCategory.NonSpacingMark)
            {
                sb.Append(stFormD[ich]);
            }
        }

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

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

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

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