在数据库中搜索字符串的子字符串 [英] search database for string's substrings

查看:95
本文介绍了在数据库中搜索字符串的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向所有专家问好.. :)我在C#(和一般编程)领域非常陌生,所以如果我的描述不够清楚,我深表歉意.这是我想做的任务:doh:.我有一个字符串让我们说:

Hello to all experts.. :) I''m very new in C#(and programming in general), so i apologize if my description isn''t as clear as it could be. Here is my wanna-do task :doh: . I have a string let''s say:

string final_word="New Bacliff Texas United States";



我想做的是检查此字符串的每个可能的子字符串,以查找数据库中的匹配项.
更清楚地说,首先我将检查数据库的final_word字符串,如果没有找到匹配项,我想搜索字符串"New Bacliff Country United",如果找到匹配项,我想搜索字符串"United".如果两个字符串均未找到匹配项,我想搜索字符串"New Bacliff Country"和字符串"United States".如果找到"United States"匹配项.我将继续在字符串"New Bacliff Country"的子字符串中寻找匹配项,这意味着我将寻找"New Bacliff"和"Country","Bacliff Country"等.最后,如果没有找到匹配项子字符串我将搜索字符串中的每个单词.请记住,我事先不知道原始字符串的大小. 我希望我能阐明我的观点.
有什么主意吗?我不知道该怎么做,将字符串分割成一个数组和连接数组的项? :((
感谢您的提前帮助!!
任何答案都可以帮助我!!!!!



what i want to do is to check every possible substring of this string for a match in a database.
To be more clear, at first I''ll check for the final_word string to the database,if no matches found,I want to search for the string "New Bacliff Country United",if I find a match i want to search for the string "United".If no matches found for both string i want to search for string "New Bacliff Country" and for the string "United States".If a match is found for the "United States". I will keep looking for matches in substrings of the string "New Bacliff Country",which means that i will look for "New Bacliff" and "Country","Bacliff Country" etc.At the end if no matches found for none of the substrings i will search for each word of the string. Keep in mind that i don''t know in advance the size of the original string..
I hope i made my point clear.
Any ideas??I don''t know what to do split the string create an array and the join array''s items?? :((
Thanks for your help in advance!!!
Any answer could help me!!!!

推荐答案

如果您只想将字符串拆分成单个单词,请使用String.Split或其重载之一. br/>
如果您还想专门检查这些单词的组合,请从子字符串列表中创建所有可能的单词组合的集合.

[更新]
----------
这是一篇有关生成排列的相当不错的文章:

http://msdn.microsoft.com/en-us/library/aa302371.aspx [ ^ ]
If you just want to split the string into individual words, then use String.Split or one of its overloads.

If you also want to specifically check for combinations of those words, then create a collection of all word combinations possible from your list of sub-strings.

[Update]
----------
Here''s a fairly good article on generating permutations:

http://msdn.microsoft.com/en-us/library/aa302371.aspx[^]


要通过正则表达式创建子字符串,请参见此处 [ ^ ].
To create substrings via regex, see here[^].


这篇关于在数据库中搜索字符串的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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