Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.40/5 (2 votes)
See more:
i have a text box in my app in which i enter emails.

with a button click i want that text to be added in list box without @domain.com.
Posted
Comments
[no name] 22-Jul-14 12:55pm    
And you are unable to use the Split() function for some reason?
Member 10579673 22-Jul-14 12:58pm    
how to split?
[no name] 22-Jul-14 13:00pm    
http://msdn.microsoft.com/en-us/library/system.string.split(v=vs.110).aspx
Sergey Alexandrovich Kryukov 22-Jul-14 13:38pm    
It depends on what do you call "TextBox". Which one? Full type name, please.
—SA
Member 10579673 22-Jul-14 13:42pm    
txtMail.Text

You can get the help of MailAddress Class

http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx[^]

example :
C#
MailAddress Emailaddress = new MailAddress("testemail@domain.com");
string username = Emailaddress.User;
string domain = Emailaddress.Host;


output :

username : testemail
domain : domain.com
 
Share this answer
 
v3
Do it like this :-
on click event do the following coding;-
C#
private void button1_Click(object sender, EventArgs e)
        {
            string phase = textBox1.Text;
            char[] delim = new char[] {'@'}; //define '@' as a delimiter required for split() method
            string[] word; //* split method return output in array of sting*/
            word = phase.Split(delim, 2); /* return two string one the username (abc) from email-id and second the remaining one.*/
            listBox1.Items.Add(word[0]); //adds the first string (username) from the array.
            textbox1.clear();
            textbox1.focus(); 
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900