首页 > 其他 > 详细

查找区配的订单号

时间:2019-05-14 12:16:59      阅读:105      评论:0      收藏:0      [点我收藏+]

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

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

技术分享图片

 

技术分享图片
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行代码,可以修改一下,更加简洁:

技术分享图片

 

技术分享图片
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

 

查找区配的订单号

原文:https://www.cnblogs.com/insus/p/10860870.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!