如何在 PowerShell 中删除重音符号?
我有一个在 Microsoft Exchange Server 和 Active Directory 中创建用户的脚本。因此,尽管在西班牙用户名带有重音符号或 ñ 的情况很常见,但我希望避免使用它们,以免用户名在旧系统中造成任何不兼容。
那么,如何清洁这样的绳子呢?
$name = "Ramón"
要那样吗? :
$name = "Ramon"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据 ip. 的回答,这是 Powershell 版本。
输出:
As per ip.'s answer, here is the Powershell version.
Output:
好吧,我可以帮助您编写一些代码......
我最近在 ac# 项目中使用了它来从电子邮件地址中删除:
我想我现在可以说“扩展到 PowerShell 脚本/表单是留给读者的”。 ...希望有帮助...
Well I can help you with some of the code.....
I used this recently in a c# project to strip from email addresses:
I guess I can now say 'extending into a PowerShell script/form is left to the reader'.... hope it helps....
针对非 C# 编码人员的 @ip 的另一个 PowerShell 翻译;o)
Another PowerShell translation of @ip for non C# coders ;o)
在上面示例的帮助下,我在管道中使用了这个“one-liner:”(仅在 Win10 中测试):
结果:
With the help of the above examples I use this "one-liner:" in pipe (tested only in Win10):
Result:
您可以在 NFD 字符串上使用 -replace 来删除组合标记,而不是创建字符串生成器并循环字符:
Instead of creating a stringbuilder and looping over characters, you can just use -replace on the NFD string to remove combining marks:
另一种解决方案...在 PowerShell 中快速“重用”您的 C#(C# 代码积分在网络某处丢失)。
Another solution... quickly "reuse" your C# in PowerShell (C# code credits lost somewhere on the net).