Retrieve Name and Email from string using C# and VB.Net in ASP.Net

Waghmare
 
on Sep 13, 2021 10:42 PM
467 Views

Hi Team,

I have a below string value which contains angular brackets.

Ravi W<raviw@gmail.com>

Where it is only allowing me to add raviw@gmail.com

I want the name and email id with it.

Where angular brackat does not allowed.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Sep 14, 2021 03:51 AM

Hi Waghmare,

Refer below code.

Code

C#

string nameEmail = "Ravi W<raviw@gmail.com>";
if (nameEmail.Split('<').Length >= 2)
{
    string name = nameEmail.Split('<')[0];
    string email = nameEmail.Split('<')[1].Replace(">", "");
}

VB.Net

Dim nameEmail As String = "Ravi W<raviw@gmail.com>"
If nameEmail.Split("<"c).Length >= 2 Then
    Dim name As String = nameEmail.Split("<"c)(0)
    Dim email As String = nameEmail.Split("<"c)(1).Replace(">", "")
End If

Screenshot