Username Creation with spaced last name

We recently ran into an issue with the new user provisioning where if a user has two last names for example First Name: John Last Name Doe sDoe, it creates the account with John.Doe sDoe@mycompany.com When this syncs with Azure its going to throw lots of errors we need a way to only use John.Doe@mycompany.com

Try using this C# Substring expression that takes the first word from a string

Person.LastName.Substring(0, Person.LastName.IndexOf(" "))

Also, I think this would work as well

Person.LastName.Split(’ ').FirstOrDefault()