ソースを参照

Merge branch 'master' of https://github.com/yuzhengyang/Fork

yuzhengyang 3 年 前
コミット
7c53f113c5

+ 1 - 0
Azylee.Utils/Azylee.Core/Azylee.Core.csproj

@@ -87,6 +87,7 @@
     <Compile Include="DataUtils\StringUtils\Str.cs" />
     <Compile Include="DataUtils\StringUtils\StringArrayTool.cs" />
     <Compile Include="DataUtils\StringUtils\StringExtension.cs" />
+    <Compile Include="DataUtils\StringUtils\StringGenerator.cs" />
     <Compile Include="DataUtils\StringUtils\StringTool.cs" />
     <Compile Include="DataUtils\UnitConvertUtils\ByteConvertTool.cs" />
     <Compile Include="DbUtils\DbModels\DatabaseType.cs" />

+ 1 - 0
Azylee.Utils/Azylee.Core/DataUtils/StringUtils/StringExtension.cs

@@ -14,6 +14,7 @@ namespace Azylee.Core.DataUtils.StringUtils
         {
             string s = "Hello Extension Methods";
             int i = s.WordCount();
+            s.Ok();
         }
         /// <summary>
         /// 判断字符串 非null、""、空格(Not NullOrWhiteSpace)

+ 57 - 0
Azylee.Utils/Azylee.Core/DataUtils/StringUtils/StringGenerator.cs

@@ -0,0 +1,57 @@
+using Azylee.Core.DataUtils.CollectionUtils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.Core.DataUtils.StringUtils
+{
+    public class StringGenerator
+    {
+        /// <summary>
+        /// 通过数字区间生成一组字符串(支持一个[-]区间)
+        /// </summary>
+        /// <param name="s"></param>
+        /// <returns></returns>
+        public static List<string> CreateByNumberSection(string s)
+        {
+            List<string> resultList = new List<string>();
+            int startNumber = 0, stopNumber = 0, lens = 1;
+            string startString = "", stopString = "", arrow = "<";
+
+            string[] sp = s.Split('[', ']');
+            foreach (string item in sp)
+            {
+                if (arrow == "-") arrow = ">";
+
+                if (item.Contains("-"))
+                {
+                    string[] numbers = ArrayTool.Formatter<string>(item.Split('-'), 2);
+                    if (int.TryParse(numbers[0], out startNumber) && int.TryParse(numbers[1], out stopNumber))
+                    {
+                        lens = numbers[0].Length;
+                        arrow = "-";
+                    }
+                }
+
+                if (arrow == "<") startString += item;
+                if (arrow == ">") stopString += item;
+
+            }
+            if (startNumber < stopNumber)
+            {
+                for (int i = startNumber; i <= stopNumber; i++)
+                {
+                    string number = i.ToString();
+                    if (number.Length < lens)
+                    {
+                        number = number.PadLeft(lens, '0');
+                    }
+                    resultList.Add(startString + number + stopString);
+                }
+            }
+            if (!Ls.Ok(resultList)) resultList.Add(s);
+            return resultList;
+        }
+    }
+}

+ 16 - 9
Azylee.Utils/Tests/Test.YeahWeb/Program.cs

@@ -1,10 +1,12 @@
-using Azylee.Core.LogUtils.SimpleLogUtils;
+using Azylee.Core.DataUtils.StringUtils;
+using Azylee.Core.LogUtils.SimpleLogUtils;
 using Azylee.Jsons;
 using Azylee.YeahWeb.BaiDuWebAPI.dwz;
 using Azylee.YeahWeb.BaiDuWebAPI.IPLocationAPI;
 using Azylee.YeahWeb.ExtWebAPI.IPAddressAPI;
 using Azylee.YeahWeb.ExtWebAPI.IPCNAPI;
 using System;
+using System.Collections.Generic;
 
 namespace Test.YeahWeb
 {
@@ -14,17 +16,22 @@ namespace Test.YeahWeb
         {
             //Log log = new Log(true,LogLevel.All,LogLevel.All);
 
+            string s = "org_plu_share[0-500]";
+            List<string> list = StringGenerator.CreateByNumberSection(s);
+            foreach (var item in list)
+            {
+                Console.Write(item);
+                Console.Write("\t");
+            }
 
 
+            // var s = IPLocationTool.GetLocation();
+            //var st =  PublicIPAddressTool.GetPublicIP();
+            // var sss = IPCNTool.Get();
+            // if (s != null)
+            // {
 
-
-            var s = IPLocationTool.GetLocation();
-           var st =  PublicIPAddressTool.GetPublicIP();
-            var sss = IPCNTool.Get();
-            if (s != null)
-            {
-
-            }
+            // }