如何从文本框C中删除部分文本# [英] How Do I Remove Some Part Of Text From Textbox C#
本文介绍了如何从文本框C中删除部分文本#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有一个文本框,我在其中输入电子邮件。
点击按钮我希望在没有@domain的列表框中添加该文本.com。
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.
推荐答案
您可以获得 MailAddress Class 的帮助
http://msdn.microsoft.com/en-us/library/system .net.mail.mailaddress.aspx [ ^ ]
示例:
You can get the help of MailAddress Class
http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx[^]
example :
MailAddress Emailaddress = new MailAddress("testemail@domain.com");
string username = Emailaddress.User;
string domain = Emailaddress.Host;
输出:
用户名: testemail
域名: domain.com
这样做: -
点击事件进行以下编码; -
Do it like this :-
on click event do the following coding;-
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();
}
这篇关于如何从文本框C中删除部分文本#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文