刚刚有网友在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) { Listlist = new List () { "XS443694739104075776","","YP443694739104075776" }; var tList = new List (); 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" }; }}
上面#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); } } }