刚刚有网友在QQ问及,根据订单前缀,去查找与前缀匹配的订单号。

Insus.NET在控制台应用程序中,使用普通的方法来实现,参考下面代码示例:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

查找区配的订单号 随笔 第1张

 

查找区配的订单号 随笔 第2张
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplicationDemo.Geometric;

namespace ConsoleApplicationDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>() {
                "XS443694739104075776","","YP443694739104075776"
            };

            var tList = new List<string>();

            foreach (var item in FilterPrefixOrderNoList)
            {
                foreach (var co in list)
                {
                    if (!string.IsNullOrEmpty(co) && co.Length >= item.Length && item == co.Substring(0, item.Length))
                    {
                        tList.Add(co);
                    }
                }
            }


            //输出
            foreach (var rst in tList)
            {               
                Console.WriteLine(rst);
            }
        }

        public static string[] FilterPrefixOrderNoList = { "TS", "XS", "YP" };
    }

}
Source Code

 

上面#6行代码,可以修改一下,更加简洁:

查找区配的订单号 随笔 第4张

 

查找区配的订单号 随笔 第5张
foreach (var item in FilterPrefixOrderNoList)
            {
                foreach (var co in list)
                {
                    // if (!string.IsNullOrEmpty(co) && co.Length >= item.Length && item == co.Substring(0, item.Length))

                    if (co.StartsWith(item))
                    {
                        tList.Add(co);
                    }
                }
            }
Source Code

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄