从带有逗号分隔的Text的TextBox中读取值 [英] Read values from a TextBox with comma separated Text

查看:78
本文介绍了从带有逗号分隔的Text的TextBox中读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个TextBox控件,我在这里使用Ajax AutoComplete扩展程序供最终用户输入要保存的人员的电子邮件地址(以逗号分隔),我的问题是在后面的代码中我想读取用户输入的每个电子邮件地址分别保存,以便我可以将其另存为数据库中的单独记录.如何阅读每个电子邮件地址后面的单独代码?

谢谢,

Chetan.

Hi,

I have a TextBox control where i am using Ajax AutoComplete extender for the end user to enter email address of the people they want to save separated by a comma, my problem is that in code behind I want to read each email address entered by the user separately so that i can save it as an individual record in the database, How do i Read each email address separately code behind?

Thanks,

Chetan.

推荐答案

Sugato的解决方案显示了正确的想法,但是代码中存在许多错误.
这是split方法的更安全版本:

The solution by Sugato show correct idea, but there are number of bugs in code.
This is safer version of the split method:

string [] emailArr =
    strEmailAddress.Split(
        new char[] {',', ' '},
        StringSplitOptions.RemoveEmptyEntries);



—SA



—SA



您可以使用String.Split函数来分隔以逗号分隔的电子邮件地址.
如果在输出中使用String.Split('','') thn,则将获得这些电子邮件地址的数组.代码将如下所示:

Hi,
you can use String.Split function to separate the comma separated email address.
If you use String.Split('','') thn in the output you will get an array of those email addresses.the code ll be as follows:

string strEmailaddress = Textbox.text;
string [] EmailArr = strEmailAddress.split(',');



现在,如果有多个值,则该数组将为



Now if there is multiple value then the array will be

EmailArr[]={"1@gmial.com", "2@gmail.com"};



现在,您可以通过EmailArr[0]EmailArr[1]
从此数组中提取单个元素 并可以插入数据库.

希望对您有帮助.



Now you can take single element from this array by EmailArr[0] and EmailArr[1],
and can insert into DB.

Hope this will help you.


这篇关于从带有逗号分隔的Text的TextBox中读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆