就像C#.net中的运算符一样 [英] Like operator in conents in C#.net

查看:68
本文介绍了就像C#.net中的运算符一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在进行基于包含的字符串搜索。



We are doing string search based on contains.

string str="Hello iam saritha help me about this problem".

If(str.contains( array[i])==true)
{
  
}





我们给这样的字符串:



llo。



如果单词与llo完全相同,那么只显示输出。



但这将基于他llo最后三个单词。



我们想要准确的单词llo。



we are giving the string like this:

"llo".

If the word exactly like "llo" then only display the output.

But it will comes based on he"llo" last three words.

We want exact word "llo".

推荐答案

你可以使用正则表达式 [ ^ ]:快速搜索产生 this [ ^ ]。
You could use a regular expression[^]: quick search yields this[^].


String.Contains适用于完全匹配,但对于更复杂的事情它不能很好地工作。你可以用空格包围你的单词:

String.Contains is good for exact matches, but it doesn't work too well for more complex things. You could do it by surrounding your word with spaces:
If(str.contains(string.Format(" {0} ", array[i]))==true)

但是当你得到标点符号时就会失败。

你考虑过正则表达式吗?

But that will fail when you get punctuation.
Have you considered a Regex?


你好

你有很多方法可以做到这一点。

一个可能是

Hi
There are many ways yo can do this.
One may be
String str = "Hello, Hello bssjd sbndjsjdas anasj hello.hello;";
            string[] _words=str.Split(new char[] { ' ',';',',','.'});
            var _matches = _words.Where(s => s.Equals("MatchWord", StringComparison.InvariantCultureIgnoreCase)).ToList();


这篇关于就像C#.net中的运算符一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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