Getting name in an email address

I got this code to retrieve the name within the email address:
StrConv(Split(emailAddress, “@”.ToCharArray)(0).Replace(“.”, " "), VbStrConv.ProperCase)

However when I try to run it I am getting this error:
Write Line: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.

When I run this using VB, Windows-Legacy it runs well. How do I make this work using VB, Windows setting?

Thanks.

Hi @redanime94

You can use a RegEx to extract the data and then do the necessary string manipulations:

^[^@]+

image

Use the following expression:

userName = System.Text.RegularExpressions.Regex.Matches(emailAddress,"^[^@]+").Vaue

Then you can replace the . with a space.

Hope this helps,
Best Regards.

Thanks for that. I took a cue from your suggestion and used the following:

System.Text.RegularExpressions.Regex.Matches(emailAddress,“[1]+”).ToString.Replace(“.”, " ")

alternately, I also had this:
Split(emailAddress, “@”.ToArray)(0).Replace(“.”, " ")


  1. ^@ ↩︎

@redanime94 ,
Please try this one

Split("User.Name@Gmail.com","@")(0).Replace("."," ")

image

Regards,

Yup had the same thing above. Thanks for that.

I just need to make the name now in proper case.

Got it!

System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(NameFromEmail)
where
NameFromEmail is the below

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.