如何拆分文本框值 [英] How to split the textbox values
问题描述
嗨
在我的数据库位置字段中是
钦奈,孟买,浦那
孟买金奈
钦奈,班加罗尔
班加罗尔,浦那
德里,浦那
钦奈
孟买
chennai
如果我不确定,我插入文本框的值是chennai,表示我想要这样的输出
钦奈,孟买,浦那
孟买金奈
钦奈,班加罗尔
chennai
chennai
我插入另一个值是chennai,孟买意味着我想要这样的输出
钦奈,孟买,浦那
孟买金奈
钦奈,班加罗尔
chennai
chennai
孟买
请找出asp.net或c#
的编码路径
问候
Bala
Hi
In my database location fields is
chennai, mumbai, pune
chennai, mumbai
chennai, bangalore
bangalore, pune
del pune
chennai
mummbai
chennai
If my doubt''s I insert the textbox values is chennai means i want output like this
chennai, mumbai, pune
chennai, mumbai
chennai, bangalore
chennai
chennai
and I insert the another values is chennai, mumbai means i want output like this
chennai, mumbai, pune
chennai, mumbai
chennai, bangalore
chennai
chennai
mumbai
Plz find out the coding path asp.net or c#
Regards
Bala
推荐答案
捕获要插入到文本框中的字符串,并使用 LIKE运算符数据库以获取匹配结果.
很抱歉,如果出现错误,我们可以为您指明正确的方向,但是我们无法为您编码.
您可以从这里获得一些学习经验
http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html [ ^ ]
Capture the string that you are inserting into the text box and use the LIKE operator on the database to get matching results.
And sorry we can point you to right direction if there is a mistake,but we cannot code for you.
You can get some learning experience from here
http://www.homeandlearn.co.uk/csharp/csharp_s12p12.html[^]
static void Main(string[] args)
{
List<string> sourceFromDB = new List<string>
{
"chennai, mumbai, pune"
,"chennai, mumbai"
,"chennai, bangalore"
,"bangalore, pune"
,"delhi, pune"
,"chennai"
,"mummbai"
,"chennai"
};
string text = "chennai,mummbai";
// Start. Maybe the follow code is what you need.^_^
string[] allKey = (text ?? "").Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
List<string> result = (from sc in sourceFromDB
let scTp = sc.Split(new char[]{',',' '},StringSplitOptions.RemoveEmptyEntries)
where scTp.Distinct().Intersect(allKey).Count() > 0
select sc).ToList();
// End.
foreach (string str in result)
{
Console.WriteLine(str);
}
Console.ReadKey();
}</string></string></string>
这篇关于如何拆分文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!