Browse Source

添加通配符匹配字符串方法

yuzhengyang 8 years ago
parent
commit
8b953fc16b

+ 1 - 9
Fork.Net/Test/Y.Test/Program.cs

@@ -1,6 +1,7 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Windows.Forms;
 using Y.Test.Commons;
 using Y.Test.Commons;
@@ -20,15 +21,6 @@ namespace Y.Test
         [STAThread]
         [STAThread]
         static void Main()
         static void Main()
         {
         {
-            //string param = string.Format("id={0}&text={1}", "123123123", "123123123");
-            ////string rs = HttpTool.Post("http://localhost:20001/Data/Post", param);
-            //WebAPIMessageModel rs = HttpTool.Post<WebAPIMessageModel>("http://localhost:20001/Data/Post", param);
-
-            //var a = DirTool.Parent(@"D:\Temp\流量测试\");
-            //var b = DirTool.Parent(@"D:\Temp");
-            //var c = DirTool.Parent(@"D:\");
-            //var d = DirTool.Parent(@"\\\\");
-            
             Application.EnableVisualStyles();
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new MainForm());
             Application.Run(new MainForm());

+ 21 - 1
Fork.Net/Y.Utils/DataUtils/StringUtils/StringTool.cs

@@ -1,13 +1,14 @@
 //************************************************************************
 //************************************************************************
 //      https://github.com/yuzhengyang
 //      https://github.com/yuzhengyang
 //      author:     yuzhengyang
 //      author:     yuzhengyang
-//      date:       2017.3.29 - 2017.8.3
+//      date:       2017.3.29 - 2017.8.16
 //      desc:       字符串工具类
 //      desc:       字符串工具类
 //      Copyright (c) yuzhengyang. All rights reserved.
 //      Copyright (c) yuzhengyang. All rights reserved.
 //************************************************************************
 //************************************************************************
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Text;
 using System.Text;
+using System.Text.RegularExpressions;
 using Y.Utils.DataUtils.Collections;
 using Y.Utils.DataUtils.Collections;
 
 
 namespace Y.Utils.DataUtils.StringUtils
 namespace Y.Utils.DataUtils.StringUtils
@@ -64,5 +65,24 @@ namespace Y.Utils.DataUtils.StringUtils
             }
             }
             return 0;
             return 0;
         }
         }
+        /// <summary>
+        /// 根据通配符验证字符串
+        /// </summary>
+        /// <param name="s">字符串</param>
+        /// <param name="pattern">通配符:%和_</param>
+        /// <returns></returns>
+        public static bool IsMatch(string s, string pattern)
+        {
+            try
+            {
+                //key = key.Replace("%", @"[\s\S]*").Replace("_", @"[\s\S]");
+                pattern = pattern.Replace("%", ".*").Replace("_", ".");
+                return Regex.IsMatch(s, pattern);
+            }
+            catch
+            {
+                return false;
+            }
+        }
     }
     }
 }
 }