当前位置: 首页 > news >正文

C# 检查字符串是否包含在另一个字符串中

string shopList = "我是大浪,你的小狼";
this.ShopId="你的小狼";
bool existsShopId = false;
if (!string.IsNullOrEmpty(shopList))
{existsShopId = shopList.Split(',').Any(part => part.Trim() == this.ShopId);
}

检查 goodsIdSet 中的每个元素是否都在 bindGoodsListIdSet 中

string goodsId= "我是大浪";
string BindGoodsListId="你的小狼,我是大浪";
// 将字符串拆分为集合
HashSet<string> goodsIdSet = new HashSet<string>(goodsId.Split(','));
HashSet<string> bindGoodsListIdSet = new HashSet<string>(BindGoodsListId.Split(','));
// 检查 goodsIdSet 中的每个元素是否都在 bindGoodsListIdSet 中
bool allGoodsIdsExist = goodsIdSet.All(id => bindGoodsListIdSet.Contains(id));

检查 goodsIdSet 中的任意一个元素是否在 bindGoodsListIdSet 中

string goodsId= "我是大浪";
string BindGoodsListId="你的小狼,我是大浪";
// 将字符串拆分为集合
HashSet<string> goodsIdSet = new HashSet<string>(goodsId.Split(','));
HashSet<string> bindGoodsListIdSet = new HashSet<string>(BindGoodsListId.Split(','));
// 检查 goodsIdSet 中的任意一个元素是否在 bindGoodsListIdSet 中
bool anyGoodsIdExists = goodsIdSet.Any(id => bindGoodsListIdSet.Contains(id));

相关文章:

  • 集合框架--Set集合详解
  • rocketMQ 常见问题记录
  • 使用最新threejs复刻经典贪吃蛇游戏的3D版,附完整源码
  • [Java · 初窥门径] Java 语言初识
  • 拉取windows的docker镜像转到服务器上构建服务镜像
  • 裸金属服务器的应用场景有哪些?
  • 深度学习| Deep Snake环境配置+训练+预测评估(超全面)
  • 如何快速安装和使用AI数字人?AIStarter详细教程与操作指南
  • 【工具】gtest
  • Spring数据访问全解析:ORM整合与JDBC高效实践
  • 楼梯上下检测数据集VOC+YOLO格式5462张2类别
  • 【国家能源集团生态协作平台-注册/登录安全分析报告】
  • 【疑难杂症】【VS Code】VS Code连接不上远程服务器
  • [TriCore][TC3XX][用户手册] - 16.中断控制器 - IR
  • 计算机视觉——基于使用 OpenCV 与 Python 实现相机标定畸变校正
  • C++数据收发管道:构建高效的数据传输通道
  • 【天外之物】概念区分:磅(力)与磅(质量)
  • mysql8.0 创建全文索引及mysql 8.0.32创建全文索引报错 Duplicate entry null-null的解决方案
  • 从数据质量看起,数据治理在做什么?
  • Java集合框架深度解析:HashMap、HashSet、TreeMap、TreeSet与哈希表原理详解
  • 延安市委副书记马月逢已任榆林市委副书记、市政府党组书记
  • 西安旅游:2024年营业收入约5.82亿元,同比增长5.88%
  • 上海地铁18号线二期长轨贯通,预计今年年底开通初期运营
  • 中央宣传部原副部长张建春被提起公诉
  • 释新闻|加州诉特朗普政府:美国最大经济体为何打响关税阻击战?
  • 山东海事局通报3起商渔船碰撞事故:将严打违反避碰规则等违法行为