模式在C#中匹配两个字符串 [英] Pattern Matching two string in c#

查看:68
本文介绍了模式在C#中匹配两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要一种有效的方法来匹配两个与常用字符匹配的文本模式.

示例:

Hi,

I need a efficient way match two text pattern that match common characters.

Example:

string text = "Poland vs Greece";
         string pattern = "Poland v Greece";

         Regex r = new Regex(pattern, RegexOptions.IgnoreCase);

         Match m = r.Match(text);
         ArrayList results = new ArrayList();
         while (m.Success)
         {
             results.Add(m.Groups[0].Value);

             m = m.NextMatch();
         }

         string[] matchesStringArray = (string[])results.ToArray(typeof(string));

         for (int i = 0; i < matchesStringArray.Length; i++)
         {
             Console.Write(matchesStringArray[i]);
         }



阿森纳v桑德兰AFC
阿森纳v桑德兰
阿森纳v桑德兰v

使用任何模式匹配算法比较上面的字符串.

尽快给我回复. (下次我会更谦虚的.)

谢谢您



Arsenal FC v Sunderland AFC
Arsenal v Sunderland
Arsenal FC v Sunderland V

Compare the above string using any pattern matching algorithm.

Send me reply as soon as possible. (I will be more humble next time.)

Thank you

推荐答案

^ ],它在您身边坏了吗?

首先尝试在您身边做一些事情,然后在遇到问题时发表您的问题.

这根本不合适.

您甚至可以尝试在 CodeProject 上搜索> [
What happened to Google[^], is it broken at your side?

Try something by your side first, then post your questions if you get stuck''d somewhere.

This is not at all appropriate.

You can even try search on CodeProject[^] with same question and get many similar solved answers.




请查看
扩展的搜索方法 [
Hi,

Please have a look at Extended search method[^]

You can similarly create your own method for comparison. it''s all depend on what you would like to achieve.

hope this link will help you,

Thanks
-Amit Gajjar.


这篇关于模式在C#中匹配两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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