How do I get the left of "@" character from the emailID string "feedback@abc.com" in C#
开发者_如何转开发Thanks
string email = "feedback@abc.comm";
int index = email.IndexOf("@");
string user = (index > 0 ? email.Substring(0, index) : "");
var email = "feedback@abc.com";
var name = email.Substring(0, email.IndexOf("@"));
You'll want to do some sanity checks like make sure it's not null and that you actually find the "@" sign.
string username = new System.Net.Mail.MailAddress("feedback@abc.com").User;
email.Split('@').Last() email.Split('@').First()
Use the Substring and IndexOf methods:
var email = "feedback@abc.com";
var user = email.Substring(0, email.IndexOf("@"))
Something like this should work.
string email = "test@testdomain.com";
string user = email.Substring(0, email.IndexOf("@"));
精彩评论