-3

I am tasked with generating an email address for new users in our environment who may have special characters (such as an umlaut and accents) in their full names. While some email systems can handle these characters I am being told to generate email addresses that can convert these characters to a standard ASCII format.

So for example, John Señior would be created as john.senior@... and Jane Fraü would be created as jane.frau@...

Has anyone found a regex expression or library that can handle such a requirement.

UPDATE - I am planning on performing the replacement in PowerShell, but could use any Windows compiled libraries as well.

Dscoduc
  • 7,714
  • 10
  • 42
  • 48
  • Which language are you using? – ctwheels Jun 24 '19 at 17:19
  • A quick search yields many answers for this in different languages, e.g. https://stackoverflow.com/q/3322152/1954610 -- Which tool/language do you have in mind? – Tom Lord Jun 24 '19 at 17:20
  • 1
    @ctwheels - Thanks, that answer definitely helped answer my question, but perhaps my question and answer will help those looking to do something like this with PowerShell... – Dscoduc Jun 24 '19 at 18:02

1 Answers1

2

Having a better understanding of what I was trying to do, aka removing diacritics, I was directed to this article How do I remove diacritics (accents) from a string in .NET? which provided a good solution that I converted into use for PowerShell:

$name = "Jane Fraü"
$tempBytes = [System.Text.Encoding]::GetEncoding("ISO-8859-8").GetBytes($name)
$newName = [System.Text.Encoding]::UTF8.GetString($tempBytes)
Write-Host $newName
Jane Frau
Dscoduc
  • 7,714
  • 10
  • 42
  • 48
  • Failing test: `$name = "א"`. This isn't the right way to do it because it is doing other things that you don't want. – Tom Blodget Jun 24 '19 at 18:38
  • @Tom Blodget - any ideas on a better way to handle this? Right now we have to do it manually... – Dscoduc Jun 24 '19 at 19:06
  • I think the linked question Will answers that are useful to you. BTW-it's a sad thing when IT has to tell users how they can't write their own names. – Tom Blodget Jun 24 '19 at 19:13