搜索字符串 [英] Search a String

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

问题描述

关于如何在C#中进行搜索的任何想法

范围或单词

例如


我想在字符串中搜索鸡肉

string s1 =" This is Great Chicken" ;;

string s2 =" Chicken" ;;

返回s1.IndexOf(s2)> = 0

诀窍是我如何搜索:搜索的人

拼写错误单词Chickin(一直发生);


string s1 =" This is Great Chicken" ;;

string s2 =" Chickin";


返回???





最糟糕

string s1 =" This is Great Chickin" ;;

string s2 =" Chicken";


人输入拼写错误的单词Chicken;


string s1 =" This is Great Chickin";

string s2 =" Chicken";

解决方案

10月2日,2:26 * pm,S< scottremi ... @ yahoo.comwrote:


关于我怎么做的任何想法在C#内搜索

范围或单词


例如


我想在中搜索鸡字符串


string s1 =" This is Great Chicken" ;;

string s2 =" Chicken";

return s1.IndexOf(s2)> = 0


诀窍是我如何搜索:搜索的人

拼错了单词Chickin(Happens all时间);


string s1 =" This is Great Chicken" ;;

string s2 =" Chickin";

返回???





最糟糕

string s1 =" This是Great Chickin" ;;

string s2 =" Chicken";


人输入搜索短语拼错单词Chicken;


string s1 ="这是Great Chickin " ;;

string s2 =" Chicken" ;;



查看Regex名称空间。


如果您搜索诸如Chickin之类的内容。在一个没有
的字符串中包含这个标记,例如This is Great Chicken,你会想要返回什么?b $ b?我不希望它返回任何东西。也许你

想做一些类似谷歌的关键词建议,如果用户输入

有一些拼写错误?


10月2日,2:51 * pm,作者< gnewsgr ... @ gmail.comwrote:


10月2日,2:26 * pm,S< scottremi ... @ yahoo.comwrote:


关于如何在C#中进行搜索的任何想法

范围或单词


例如


我想在字符串中搜索Chicken


string s1 =" This is Great Chicken" ;;

string s2 =" Chicken";

返回s1.IndexOf(s2)> = 0


诀窍是怎么回事我搜索:搜索的人

拼错了d Chickin(一直发生);


string s1 =" This is Great Chicken" ;;

string s2 =" Chickin" ;;


return ???




最糟糕

string s1 =" This is Great Chickin" ;;

string s2 =" Chicken" ;;


人输入拼写错误的单词Chicken;


string s1 =" This is Great Chickin" ;;

string s2 =" Chicken" ;;



查看Regex名称空间。



更正:我的意思是System.Text.RegularExpressions命名空间
http://msdn.microsoft.com/en-us/libr...pressions.aspx


正则表达式是这个命名空间的一类。


如果你搜索诸如Chickin之类的东西。在一个没有
的字符串中包含这个标记,例如This is Great Chicken,你会想要返回什么?b $ b? *我不希望它返回任何东西。 *也许你

想做一些类似谷歌的关键词建议,如果用户输入

有一些错别字?



2008年10月2日星期四11:26:38 -0700,S< sc ********* *@yahoo.com写道:


关于如何在C#中进行搜索的任何想法

范围或单词



有各种各样的技巧来处理部分匹配,因为你要b
描述。


我自己过去实际上已经实现了一个非常简单的方法,

我在目标文本

和之间进行了一种逐字符合并。搜索单词,在目标文本中找到搜索

单词最适合排除字符数最少的位置。这个

对于你给出的例子非常有效,但是否能够解决你的更普遍的目标我不能说。


如果这看起来很有希望,我或许能够挖掘代码并在此发布

。这是非常低效的,但它既小又简单,那么

哎呀? :)


您也可以谷歌搜索soundex。甚至还有关于

的维基百科文章主题:
http://en.wikipedia.org/wiki/Soundex

这是一种常用的基于语音匹配单词的技术和

如果你想要一个更基于语言而不是排版的解决方案,

这可能是一个更好的方法。


谷歌搜索在字典拼写检查算法上还出现了一些有希望的链接。


Pete


Any idea on how I would be able to do a search within C# that does
ranges or words
For example

I want to search for Chicken in the string
string s1 = "This is Great Chicken";
string s2 = "Chicken";
return s1.IndexOf(s2) >= 0

The trick is how would I search for: Person doing the search
misspelled the word Chickin (Happens all the time);

string s1 = "This is Great Chicken";
string s2 = "Chickin";

return ???

or

Worst yet
string s1 = "This is Great Chickin";
string s2 = "Chicken";

Person enter the search phrase misspelled the word Chicken;

string s1 = "This is Great Chickin";
string s2 = "Chicken";

解决方案

On Oct 2, 2:26*pm, S <scottremi...@yahoo.comwrote:

Any idea on how I would be able to do a search within C# that does
ranges or words

For example

I want to search for Chicken in the string

string s1 = "This is Great Chicken";
string s2 = "Chicken";
return s1.IndexOf(s2) >= 0

The trick is how would I search for: Person doing the search
misspelled the word Chickin (Happens all the time);

string s1 = "This is Great Chicken";
string s2 = "Chickin";

return ???

or

Worst yet
string s1 = "This is Great Chickin";
string s2 = "Chicken";

Person enter the search phrase misspelled the word Chicken;

string s1 = "This is Great Chickin";
string s2 = "Chicken";

Check out the Regex namespace.

If you search something such as "Chickin" in a string which does not
contain this token, such as "This is Great Chicken", what would you
expect to return? I wouldn''t expect it to return anything. Maybe you
wanna do something like google''s key words suggestion if user entry
has some typos?


On Oct 2, 2:51*pm, Author <gnewsgr...@gmail.comwrote:

On Oct 2, 2:26*pm, S <scottremi...@yahoo.comwrote:

Any idea on how I would be able to do a search within C# that does
ranges or words

For example

I want to search for Chicken in the string

string s1 = "This is Great Chicken";
string s2 = "Chicken";
return s1.IndexOf(s2) >= 0

The trick is how would I search for: Person doing the search
misspelled the word Chickin (Happens all the time);

string s1 = "This is Great Chicken";
string s2 = "Chickin";

return ???

or

Worst yet
string s1 = "This is Great Chickin";
string s2 = "Chicken";

Person enter the search phrase misspelled the word Chicken;

string s1 = "This is Great Chickin";
string s2 = "Chicken";


Check out the Regex namespace.

Correction: I meant the System.Text.RegularExpressions Namespace
http://msdn.microsoft.com/en-us/libr...pressions.aspx

Regex is a class of this namespace.

If you search something such as "Chickin" in a string which does not
contain this token, such as "This is Great Chicken", what would you
expect to return? *I wouldn''t expect it to return anything. *Maybe you
wanna do something like google''s key words suggestion if user entry
has some typos?



On Thu, 02 Oct 2008 11:26:38 -0700, S <sc**********@yahoo.comwrote:

Any idea on how I would be able to do a search within C# that does
ranges or words

There are a variety of techniques for dealing with partial matching as you
describe.

I''ve actually implemented a very simple approach myself in the past, in
which I do a sort of character-by-character merge between the target text
and the search word, finding the spot in the target text where the search
word fits the best with the least number of excluded characters. This
would work perfectly for the examples you gave, but whether that would
address your more general goals I can''t say.

If that sounds promising, I might be able to dig up the code and post it
here. It''s pretty inefficient, but it''s small and simple so what the
heck? :)

You might also Google for "soundex". There''s even a Wikipedia article on
the topic:
http://en.wikipedia.org/wiki/Soundex

That''s a commonly used technique for matching words based on phonetics and
if you want a solution that is based more on language than on typography,
it might be a better approach.

A Google search on "dictionary spell check algorithm" also turned up a
number of promising links.

Pete


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

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