Reputation: 80
I need to get username from email address by removing the part after "@" symbol. For example,
Dim uemail As String
Dim uname As String
umail = email_tb.Text.ToString() 'Suppose this returns [email protected]
uname = umail (and some code) 'This will return abc.xyz only
Upvotes: 0
Views: 137
Reputation: 14432
Using VB you can do this by using the Split method:
Dim umail = email_tb.Text.ToString()
Dim uname As String = Split(umail, "@")(0)
Using VB.NET you could use the Substring and the IndexOf methods to achieve this:
Dim umail = email_tb.Text.ToString()
Dim uname As String = umail.Substring(0, umail.IndexOf("@"))
Upvotes: 2
Reputation: 460118
One efficient way, use pure string methods like IndexOf
, Substring
or Remove
:
Dim uname = mail.Remove(mail.IndexOf("@"c)) ' check if IndexOf returned -1 first
You could also split by this separator:
Dim tokens As String() = mail.Split("@"c)
Dim uname = tokens.First()
Upvotes: 1