IT评测·应用市场-qidao123.com技术社区

标题: C# 查抄字符串是否包罗在另一个字符串中 [打印本页]

作者: 大号在练葵花宝典    时间: 5 天前
标题: C# 查抄字符串是否包罗在另一个字符串中
  1. string shopList = "我是大浪,你的小狼";
  2. this.ShopId="你的小狼";
  3. bool existsShopId = false;
  4. if (!string.IsNullOrEmpty(shopList))
  5. {
  6.     existsShopId = shopList.Split(',').Any(part => part.Trim() == this.ShopId);
  7. }
复制代码
查抄 goodsIdSet 中的每个元素是否都在 bindGoodsListIdSet 中
  1. string goodsId= "我是大浪";
  2. string BindGoodsListId="你的小狼,我是大浪";
  3. // 将字符串拆分为集合
  4. HashSet<string> goodsIdSet = new HashSet<string>(goodsId.Split(','));
  5. HashSet<string> bindGoodsListIdSet = new HashSet<string>(BindGoodsListId.Split(','));
  6. // 检查 goodsIdSet 中的每个元素是否都在 bindGoodsListIdSet 中
  7. bool allGoodsIdsExist = goodsIdSet.All(id => bindGoodsListIdSet.Contains(id));
复制代码
查抄 goodsIdSet 中的恣意一个元素是否在 bindGoodsListIdSet 中
  1. string goodsId= "我是大浪";
  2. string BindGoodsListId="你的小狼,我是大浪";
  3. // 将字符串拆分为集合
  4. HashSet<string> goodsIdSet = new HashSet<string>(goodsId.Split(','));
  5. HashSet<string> bindGoodsListIdSet = new HashSet<string>(BindGoodsListId.Split(','));
  6. // 检查 goodsIdSet 中的任意一个元素是否在 bindGoodsListIdSet 中
  7. bool anyGoodsIdExists = goodsIdSet.Any(id => bindGoodsListIdSet.Contains(id));
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/) Powered by Discuz! X3.4