Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left of a character in a string in C#

Tags:

c#

How do I get the left of "@" character from the emailID string "[email protected]" in C#

Thanks

like image 488
rowmark Avatar asked Jun 04 '10 02:06

rowmark


2 Answers

string email = "[email protected]";
int index = email.IndexOf("@");
string user = (index > 0 ? email.Substring(0, index) : "");
like image 172
user347594 Avatar answered Oct 06 '22 19:10

user347594


var email = "[email protected]";
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.

like image 23
Samuel Neff Avatar answered Oct 06 '22 20:10

Samuel Neff