剛剛有網友在QQ問及,根據訂單首碼,去查找與首碼匹配的訂單號。 Insus.NET在控制台應用程式中,使用普通的方法來實現,參考下麵代碼示例: using System; using System.Collections.Generic; using System.IO; using System. ...
剛剛有網友在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